All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] ata: pata_parport: add driver (PARIDE replacement)
@ 2023-02-02 12:46 Dan Carpenter
  2023-02-04 20:55 ` [PATCH] pata_parport: Fix ida_alloc return value error check Ondrej Zary
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2023-02-02 12:46 UTC (permalink / raw)
  To: linux; +Cc: linux-ide

Hello Ondrej Zary,

The patch 246a1c4c6b7f: "ata: pata_parport: add driver (PARIDE
replacement)" from Jan 23, 2023, leads to the following Smatch static
checker warning:

	drivers/ata/pata_parport/pata_parport.c:445 pi_init_one()
	warn: unsigned 'pi->dev.id' is never less than zero.

drivers/ata/pata_parport/pata_parport.c
    418 static struct pi_adapter *pi_init_one(struct parport *parport,
    419                         struct pi_protocol *pr, int mode, int unit, int delay)
    420 {
    421         struct pardev_cb par_cb = { };
    422         char scratch[512];
    423         const struct ata_port_info *ppi[] = { &pata_parport_port_info };
    424         struct ata_host *host;
    425         struct pi_adapter *pi;
    426         struct pi_device_match match = { .parport = parport, .proto = pr };
    427 
    428         /*
    429          * Abort if there's a device already registered on the same parport
    430          * using the same protocol.
    431          */
    432         if (bus_for_each_dev(&pata_parport_bus_type, NULL, &match, pi_find_dev))
    433                 return NULL;
    434 
    435         pi = kzalloc(sizeof(struct pi_adapter), GFP_KERNEL);
    436         if (!pi)
    437                 return NULL;
    438 
    439         /* set up pi->dev before pi_probe_unit() so it can use dev_printk() */
    440         pi->dev.parent = &pata_parport_bus;
    441         pi->dev.bus = &pata_parport_bus_type;
    442         pi->dev.driver = &pr->driver;
    443         pi->dev.release = pata_parport_dev_release;
    444         pi->dev.id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL);
--> 445         if (pi->dev.id < 0)
                    ^^^^^^^^^^^^^^
pi->dev.id is a u32.

    446                 return NULL; /* pata_parport_dev_release will do kfree(pi) */
    447         dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id);
    448         if (device_register(&pi->dev)) {
    449                 put_device(&pi->dev);
    450                 goto out_ida_free;
    451         }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] pata_parport: Fix ida_alloc return value error check
  2023-02-02 12:46 [bug report] ata: pata_parport: add driver (PARIDE replacement) Dan Carpenter
@ 2023-02-04 20:55 ` Ondrej Zary
  2023-02-05 19:13   ` Sergey Shtylyov
  2023-02-07  0:02   ` Damien Le Moal
  0 siblings, 2 replies; 4+ messages in thread
From: Ondrej Zary @ 2023-02-04 20:55 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: Dan Carpenter, Christoph Hellwig, Sergey Shtylyov, Jens Axboe,
	Tim Waugh, linux-block, linux-parport, linux-ide, linux-kernel

pi->dev.id is unsigned so error checking of ida_alloc return value does
not work. Fix it.

Signed-off-by: Ondrej Zary <linux@zary.sk>
---
 drivers/ata/pata_parport/pata_parport.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/ata/pata_parport/pata_parport.c b/drivers/ata/pata_parport/pata_parport.c
index 9e8ad93d7e59..294a266a0dda 100644
--- a/drivers/ata/pata_parport/pata_parport.c
+++ b/drivers/ata/pata_parport/pata_parport.c
@@ -424,6 +424,7 @@ static struct pi_adapter *pi_init_one(struct parport *parport,
 	struct ata_host *host;
 	struct pi_adapter *pi;
 	struct pi_device_match match = { .parport = parport, .proto = pr };
+	int id;
 
 	/*
 	 * Abort if there's a device already registered on the same parport
@@ -441,9 +442,10 @@ static struct pi_adapter *pi_init_one(struct parport *parport,
 	pi->dev.bus = &pata_parport_bus_type;
 	pi->dev.driver = &pr->driver;
 	pi->dev.release = pata_parport_dev_release;
-	pi->dev.id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL);
-	if (pi->dev.id < 0)
+	id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL);
+	if (id < 0)
 		return NULL; /* pata_parport_dev_release will do kfree(pi) */
+	pi->dev.id = id;
 	dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id);
 	if (device_register(&pi->dev)) {
 		put_device(&pi->dev);
-- 
Ondrej Zary


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] pata_parport: Fix ida_alloc return value error check
  2023-02-04 20:55 ` [PATCH] pata_parport: Fix ida_alloc return value error check Ondrej Zary
@ 2023-02-05 19:13   ` Sergey Shtylyov
  2023-02-07  0:02   ` Damien Le Moal
  1 sibling, 0 replies; 4+ messages in thread
From: Sergey Shtylyov @ 2023-02-05 19:13 UTC (permalink / raw)
  To: Ondrej Zary, Damien Le Moal
  Cc: Dan Carpenter, Christoph Hellwig, Jens Axboe, Tim Waugh,
	linux-block, linux-parport, linux-ide, linux-kernel

Hello!

On 2/4/23 11:55 PM, Ondrej Zary wrote:

> pi->dev.id is unsigned so error checking of ida_alloc return value does
> not work. Fix it.
> 
> Signed-off-by: Ondrej Zary <linux@zary.sk>

Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>

[...]

MBR, Sergey

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pata_parport: Fix ida_alloc return value error check
  2023-02-04 20:55 ` [PATCH] pata_parport: Fix ida_alloc return value error check Ondrej Zary
  2023-02-05 19:13   ` Sergey Shtylyov
@ 2023-02-07  0:02   ` Damien Le Moal
  1 sibling, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2023-02-07  0:02 UTC (permalink / raw)
  To: Ondrej Zary
  Cc: Dan Carpenter, Christoph Hellwig, Sergey Shtylyov, Jens Axboe,
	Tim Waugh, linux-block, linux-parport, linux-ide, linux-kernel

On 2/5/23 05:55, Ondrej Zary wrote:
> pi->dev.id is unsigned so error checking of ida_alloc return value does
> not work. Fix it.
> 
> Signed-off-by: Ondrej Zary <linux@zary.sk>

Applied. Thanks !

-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-07  0:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 12:46 [bug report] ata: pata_parport: add driver (PARIDE replacement) Dan Carpenter
2023-02-04 20:55 ` [PATCH] pata_parport: Fix ida_alloc return value error check Ondrej Zary
2023-02-05 19:13   ` Sergey Shtylyov
2023-02-07  0:02   ` Damien Le Moal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.