public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Alok Tiwari <alok.a.tiwari@oracle.com>
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org,
	alok.a.tiwarilinux@gmail.com
Subject: Re: [PATCH] PCI: Fix incorrect retval type in remove_id_store()
Date: Mon, 9 Mar 2026 17:20:40 -0500	[thread overview]
Message-ID: <20260309222040.GA624676@bhelgaas> (raw)
In-Reply-To: <20260224181434.1368066-1-alok.a.tiwari@oracle.com>

On Tue, Feb 24, 2026 at 10:14:29AM -0800, Alok Tiwari wrote:
> remove_id_store() initializes retval with -ENODEV, but retval was
> declared as size_t. Since size_t is unsigned, the negative value is
> converted to a large positive number, breaking error handling.

Does this actually cause a problem?  size_t and ssize_t are the same
size, so I would think the conversions would end up with the same
bits:

  (gdb) p (long)((unsigned long) -19)
  $1 = -19
  (gdb) p (int)((unsigned int) -19)
  $2 = -19

We have lots of sysfs show/store functions in pci-sysfs.c that return
size_t values.

> Use ssize_t to match the sysfs store() return type.
> 
> Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
> ---
>  drivers/pci/pci-driver.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index dd9075403987..b2d3dffcc4f3 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -261,7 +261,7 @@ static ssize_t remove_id_store(struct device_driver *driver, const char *buf,
>  	u32 vendor, device, subvendor = PCI_ANY_ID,
>  		subdevice = PCI_ANY_ID, class = 0, class_mask = 0;
>  	int fields;
> -	size_t retval = -ENODEV;
> +	ssize_t retval = -ENODEV;
>  
>  	fields = sscanf(buf, "%x %x %x %x %x %x",
>  			&vendor, &device, &subvendor, &subdevice,
> -- 
> 2.50.1
> 

  reply	other threads:[~2026-03-09 22:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-24 18:14 [PATCH] PCI: Fix incorrect retval type in remove_id_store() Alok Tiwari
2026-03-09 22:20 ` Bjorn Helgaas [this message]
2026-03-10  3:06   ` ALOK TIWARI
2026-03-10 16:03     ` Bjorn Helgaas
2026-03-19 15:45       ` ALOK TIWARI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260309222040.GA624676@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=alok.a.tiwari@oracle.com \
    --cc=alok.a.tiwarilinux@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox