* [PATCH v1 1/2] parport: Clean up resources correctly when parport_register_port() fails
@ 2023-10-18 14:58 Andy Shevchenko
2023-10-18 14:58 ` [PATCH v1 2/2] parport: Drop even more unneeded NULL or 0 assignments Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2023-10-18 14:58 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Sudip Mukherjee, kernel test robot, Dan Carpenter
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: 8d8ae17eb0de ("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>
---
drivers/parport/share.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index a9a9cb0477ea..048a459ce4b0 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -361,7 +361,6 @@ static void free_port(struct device *dev)
kfree(port->probe_info[d].description);
}
- kfree(port->name);
kfree(port);
}
@@ -479,16 +478,13 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,
/*
* Now that the portnum is known finish doing the Init.
*/
- tmp->name = kasprintf(GFP_KERNEL, "parport%d", tmp->portnum);
- if (!tmp->name) {
- kfree(tmp);
- return NULL;
- }
- dev_set_name(&tmp->bus_dev, tmp->name);
+ dev_set_name(&tmp->bus_dev, "parport%d", tmp->portnum);
tmp->bus_dev.bus = &parport_bus_type;
tmp->bus_dev.release = free_port;
tmp->bus_dev.type = &parport_device_type;
+ tmp->name = dev_name(&tmp->bus_dev);
+
for (device = 0; device < 5; device++)
/* assume the worst */
tmp->probe_info[device].class = PARPORT_CLASS_LEGACY;
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH v1 2/2] parport: Drop even more unneeded NULL or 0 assignments
2023-10-18 14:58 [PATCH v1 1/2] parport: Clean up resources correctly when parport_register_port() fails Andy Shevchenko
@ 2023-10-18 14:58 ` Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2023-10-18 14:58 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel; +Cc: Sudip Mukherjee
kzalloc() gives us a zeroed memory, no need to explicitly assing 0 or
NULL or similar to the members of the data structure that has been
allocated with the above mentioned API.
Note, the initializstion of full_list member is not needed anymore
as list_add_tail will rewrite the contents of the prev and next
pointers.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/parport/share.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index 048a459ce4b0..e21831d93305 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -459,7 +459,6 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,
sema_init(&tmp->ieee1284.irq, 0);
tmp->spintime = parport_default_spintime;
atomic_set(&tmp->ref_count, 1);
- INIT_LIST_HEAD(&tmp->full_list);
/* Search for the lowest free parport number. */
@@ -489,8 +488,6 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,
/* assume the worst */
tmp->probe_info[device].class = PARPORT_CLASS_LEGACY;
- tmp->waithead = tmp->waittail = NULL;
-
ret = device_register(&tmp->bus_dev);
if (ret) {
put_device(&tmp->bus_dev);
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-18 14:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-18 14:58 [PATCH v1 1/2] parport: Clean up resources correctly when parport_register_port() fails Andy Shevchenko
2023-10-18 14:58 ` [PATCH v1 2/2] parport: Drop even more unneeded NULL or 0 assignments Andy Shevchenko
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.