From patchwork Tue Mar 23 12:54:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 406867 Delivered-To: patch@linaro.org Received: by 2002:a17:906:5290:0:0:0:0 with SMTP id c16csp2115794ejm; Tue, 23 Mar 2021 05:55:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXMXHh8uC5uBMBsFwcqc/ojE5X6QQVLts1OA3hmeTSYQqW5foExwZ2Lceq4BxgaoknJDVW X-Received: by 2002:a17:906:c0c8:: with SMTP id bn8mr4692706ejb.445.1616504137745; Tue, 23 Mar 2021 05:55:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616504137; cv=none; d=google.com; s=arc-20160816; b=V2pKe62nipW4ukWAGJvqh+/0u3pau7rFsWjZS4i1BZTImZzMm9JxQ8NO8ZTod8O7Ec 9xcw7dYwBFnFNT3wl39fN5knwDwz01q6sgChnAVEvdL9NrmTVnXVLti+6uhrRXrKEtGt 8/w3mokJsWxniiQjnNtlLAAb5ULIeEIXDPahHw3Gms20gUkNdbDGlhOnG79VMKOCUBnV 2rMtWopBtITeQfxK0SfzmC/TFeRMx+CIQ3O+YzIzp+FpIdC+IjQDRa97MzQdOetSesKS weG5kwCE0NQwVZhqRqS9lpP/LO0gPq+8YZAv9RnH2u92Ddy7ZsbNA6H0f6RDndnsH7eY 50fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=KEbuo97kLh+br53IXP4OrKBgFW5cnqNHvHP83/UoHdg=; b=DgqME1M4AJw7pznbl3M/r4TWSvdMnE0h/XIeA3hv1MBbXlzx4WMyy0LVt1CO/5pqnJ NROTmxVpgD6E8kYr2lKHlMQs/CbtYJGAC4wp7nnWzGzrkqg+4YDY25q1ZoW9FqP7PQcE g36e8Waif0umoPjRk3hsBB+ISNiDrrU+1auRPCxkE9jcH1FY35piTXxu9PsWbjrc41vi TSnN9yFIi0m00bfJaRYs4Tdlw6bbTbAopFvBusJj21HbM45BkPcm/pjCLp5uzrfztFzi ODDKgAkM9fzBskOhusKFSrk/K9PSAcqz5K7P4UNVR43ma3Qv4s7kxbQtwmbOhpjzWtPO 0TBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RBQclqZJ; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hp17si10154019ejc.744.2021.03.23.05.55.37 for ; Tue, 23 Mar 2021 05:55:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RBQclqZJ; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231364AbhCWMzI (ORCPT ); Tue, 23 Mar 2021 08:55:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:40596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231316AbhCWMzE (ORCPT ); Tue, 23 Mar 2021 08:55:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 95AC560C3E; Tue, 23 Mar 2021 12:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616504103; bh=WG33UXJUD46Ak8uP8CZDERKXsKaUxMYfktLC4hORv1o=; h=From:To:Cc:Subject:Date:From; b=RBQclqZJMPL8FXz/4SC0Z4rygIpszv9wjxWHrkM0/f5sgH1RCASoiOixSCNAcbI1Y f72ggVnhdkiAY1HW1l4XGnVaO1nfM5OIeSM/aSQKGSP8CBfSrLSfC708JN6pkXij8q ZM5jdHPLKddBLAppjRizPzdMEfzBz9mN0sC4fXGaUW1sxCShI8A5j5Gy6d9WuYfQrT uKd/TxoKfCHkOCOGxE9/48XP6N8L1n/jF/uaTTUWgl74TeE/z05jeuhlwTjrI9ZT+w v4l7rA1TZzPG1Lg0xitxsJmlpcOjDB19uDv68Dijqyxfn+bP4hqRu6Jx2Amtc8ZwN1 YoTD/lZdy664w== From: Arnd Bergmann To: Jack Wang , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Arnd Bergmann , Viswas G , Ruksar Devadi , Joe Perches , Vaibhav Gupta , Christophe JAILLET , Lee Jones , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] scsi: pm8001: avoid -Wrestrict warning Date: Tue, 23 Mar 2021 13:54:23 +0100 Message-Id: <20210323125458.1825564-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Arnd Bergmann On some configurations, gcc warns about overlapping source and destination arguments to snprintf: drivers/scsi/pm8001/pm8001_init.c: In function 'pm8001_request_msix': drivers/scsi/pm8001/pm8001_init.c:977:3: error: 'snprintf' argument 4 may overlap destination object 'pm8001_ha' [-Werror=restrict] 977 | snprintf(drvname, len, "%s-%d", pm8001_ha->name, i); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/scsi/pm8001/pm8001_init.c:962:56: note: destination object referenced by 'restrict'-qualified argument 1 was declared here 962 | static u32 pm8001_request_msix(struct pm8001_hba_info *pm8001_ha) | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~ I first assumed this was a gcc bug, as that should not happen, but a reduced test case makes it clear that this happens when the loop counter is not bounded by the array size. Help the compiler out by adding an explicit limit here to make the code slightly more robust and avoid the warning. Link: https://godbolt.org/z/6T1qPM Signed-off-by: Arnd Bergmann --- drivers/scsi/pm8001/pm8001_init.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.29.2 Acked-by: Jack Wang diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c index bd626ef876da..a268c647b987 100644 --- a/drivers/scsi/pm8001/pm8001_init.c +++ b/drivers/scsi/pm8001/pm8001_init.c @@ -963,6 +963,7 @@ static u32 pm8001_request_msix(struct pm8001_hba_info *pm8001_ha) { u32 i = 0, j = 0; int flag = 0, rc = 0; + int nr_irqs = pm8001_ha->number_of_intr; if (pm8001_ha->chip_id != chip_8001) flag &= ~IRQF_SHARED; @@ -971,7 +972,10 @@ static u32 pm8001_request_msix(struct pm8001_hba_info *pm8001_ha) "pci_enable_msix request number of intr %d\n", pm8001_ha->number_of_intr); - for (i = 0; i < pm8001_ha->number_of_intr; i++) { + if (nr_irqs > ARRAY_SIZE(pm8001_ha->intr_drvname)) + nr_irqs = ARRAY_SIZE(pm8001_ha->intr_drvname); + + for (i = 0; i < nr_irqs; i++) { snprintf(pm8001_ha->intr_drvname[i], sizeof(pm8001_ha->intr_drvname[0]), "%s-%d", pm8001_ha->name, i);