Skip to content

Commit 12280cc

Browse files
andy-shevgregkh
authored andcommitted
parport: Clean up resources correctly when parport_register_port() fails
The smatch warns about uncleaned resources in case the parport_register_port() fails: parport_register_port() warn: '&tmp->full_list' not removed from list This is indeed an issue introduced when converting code to use kasprintf(). However, the whole kasprintf() dance in this case is not needed as dev_set_name() can handle the formatted input and produces the same result. So, the solution is to delegate name forming to the dev_set_name() and make device_register() error path to deal with error handling (via put_device() call). Fixes: 8d8ae17 ("parport: Use kasprintf() instead of fixed buffer formatting") Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/r/202310180809.hepZB9k6-lkp@intel.com/ Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20231018145948.1367648-1-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 63ba2d0 commit 12280cc

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

drivers/parport/share.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ static void free_port(struct device *dev)
361361
kfree(port->probe_info[d].description);
362362
}
363363

364-
kfree(port->name);
365364
kfree(port);
366365
}
367366

@@ -479,16 +478,13 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,
479478
/*
480479
* Now that the portnum is known finish doing the Init.
481480
*/
482-
tmp->name = kasprintf(GFP_KERNEL, "parport%d", tmp->portnum);
483-
if (!tmp->name) {
484-
kfree(tmp);
485-
return NULL;
486-
}
487-
dev_set_name(&tmp->bus_dev, tmp->name);
481+
dev_set_name(&tmp->bus_dev, "parport%d", tmp->portnum);
488482
tmp->bus_dev.bus = &parport_bus_type;
489483
tmp->bus_dev.release = free_port;
490484
tmp->bus_dev.type = &parport_device_type;
491485

486+
tmp->name = dev_name(&tmp->bus_dev);
487+
492488
for (device = 0; device < 5; device++)
493489
/* assume the worst */
494490
tmp->probe_info[device].class = PARPORT_CLASS_LEGACY;

0 commit comments

Comments
 (0)