* [PATCH] parport: Save a few bytes of memory
@ 2023-11-24 21:14 Christophe JAILLET
2023-12-01 15:48 ` Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2023-11-24 21:14 UTC (permalink / raw)
To: andriy.shevchenko, Sudip Mukherjee
Cc: linux-kernel, kernel-janitors, Christophe JAILLET
Most of parport_register_dev_model() callers pass a 'name' that is a
constant string.
So kstrdup_const() can be used to save the duplication of this string
when it is not needed. This saves a few bytes of memory.
Use kfree_const() accordingly when this string is freed.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/parport/share.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index e21831d93305..49c74ded8a53 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -611,7 +611,7 @@ static void free_pardevice(struct device *dev)
{
struct pardevice *par_dev = to_pardevice(dev);
- kfree(par_dev->name);
+ kfree_const(par_dev->name);
kfree(par_dev);
}
@@ -682,8 +682,8 @@ parport_register_dev_model(struct parport *port, const char *name,
const struct pardev_cb *par_dev_cb, int id)
{
struct pardevice *par_dev;
+ const char *devname;
int ret;
- char *devname;
if (port->physport->flags & PARPORT_FLAG_EXCL) {
/* An exclusive device is registered. */
@@ -726,7 +726,7 @@ parport_register_dev_model(struct parport *port, const char *name,
if (!par_dev->state)
goto err_put_par_dev;
- devname = kstrdup(name, GFP_KERNEL);
+ devname = kstrdup_const(name, GFP_KERNEL);
if (!devname)
goto err_free_par_dev;
@@ -804,7 +804,7 @@ parport_register_dev_model(struct parport *port, const char *name,
return par_dev;
err_free_devname:
- kfree(devname);
+ kfree_const(devname);
err_free_par_dev:
kfree(par_dev->state);
err_put_par_dev:
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] parport: Save a few bytes of memory
2023-11-24 21:14 [PATCH] parport: Save a few bytes of memory Christophe JAILLET
@ 2023-12-01 15:48 ` Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2023-12-01 15:48 UTC (permalink / raw)
To: Christophe JAILLET; +Cc: Sudip Mukherjee, linux-kernel, kernel-janitors
On Fri, Nov 24, 2023 at 10:14:36PM +0100, Christophe JAILLET wrote:
> Most of parport_register_dev_model() callers pass a 'name' that is a
> constant string.
>
> So kstrdup_const() can be used to save the duplication of this string
> when it is not needed. This saves a few bytes of memory.
>
> Use kfree_const() accordingly when this string is freed.
Looks good to have, hence no objection from me,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-01 15:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-24 21:14 [PATCH] parport: Save a few bytes of memory Christophe JAILLET
2023-12-01 15:48 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®