parport: Save a few bytes of memory

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>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/0eba5f2ddd142ab0f577f67e482d1152b40ee720.1700860416.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Christophe JAILLET 2023-11-24 22:14:36 +01:00 committed by Greg Kroah-Hartman
parent 190015a4bb
commit ad66d50305
1 changed files with 4 additions and 4 deletions

View File

@ -611,7 +611,7 @@ static void free_pardevice(struct device *dev)
{ {
struct pardevice *par_dev = to_pardevice(dev); struct pardevice *par_dev = to_pardevice(dev);
kfree(par_dev->name); kfree_const(par_dev->name);
kfree(par_dev); 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) const struct pardev_cb *par_dev_cb, int id)
{ {
struct pardevice *par_dev; struct pardevice *par_dev;
const char *devname;
int ret; int ret;
char *devname;
if (port->physport->flags & PARPORT_FLAG_EXCL) { if (port->physport->flags & PARPORT_FLAG_EXCL) {
/* An exclusive device is registered. */ /* An exclusive device is registered. */
@ -726,7 +726,7 @@ parport_register_dev_model(struct parport *port, const char *name,
if (!par_dev->state) if (!par_dev->state)
goto err_put_par_dev; goto err_put_par_dev;
devname = kstrdup(name, GFP_KERNEL); devname = kstrdup_const(name, GFP_KERNEL);
if (!devname) if (!devname)
goto err_free_par_dev; goto err_free_par_dev;
@ -804,7 +804,7 @@ parport_register_dev_model(struct parport *port, const char *name,
return par_dev; return par_dev;
err_free_devname: err_free_devname:
kfree(devname); kfree_const(devname);
err_free_par_dev: err_free_par_dev:
kfree(par_dev->state); kfree(par_dev->state);
err_put_par_dev: err_put_par_dev: