Commit 9920a33e authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Greg Kroah-Hartman

firmware: vpd: use kasprintf() when forming name of 'raw' attribute

When creating name for the "raw" attribute, let's switch to using
kaspeintf() instead of doing it by hand. Also make sure we handle
errors.
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: default avatarGuenter Roeck <groeck@chromium.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3eec6a1c
...@@ -190,8 +190,7 @@ static int vpd_section_create_attribs(struct vpd_section *sec) ...@@ -190,8 +190,7 @@ static int vpd_section_create_attribs(struct vpd_section *sec)
static int vpd_section_init(const char *name, struct vpd_section *sec, static int vpd_section_init(const char *name, struct vpd_section *sec,
phys_addr_t physaddr, size_t size) phys_addr_t physaddr, size_t size)
{ {
int ret; int err;
int raw_len;
sec->baseaddr = memremap(physaddr, size, MEMREMAP_WB); sec->baseaddr = memremap(physaddr, size, MEMREMAP_WB);
if (!sec->baseaddr) if (!sec->baseaddr)
...@@ -200,10 +199,11 @@ static int vpd_section_init(const char *name, struct vpd_section *sec, ...@@ -200,10 +199,11 @@ static int vpd_section_init(const char *name, struct vpd_section *sec,
sec->name = name; sec->name = name;
/* We want to export the raw partion with name ${name}_raw */ /* We want to export the raw partion with name ${name}_raw */
raw_len = strlen(name) + 5; sec->raw_name = kasprintf(GFP_KERNEL, "%s_raw", name);
sec->raw_name = kzalloc(raw_len, GFP_KERNEL); if (!sec->raw_name) {
strncpy(sec->raw_name, name, raw_len); err = -ENOMEM;
strncat(sec->raw_name, "_raw", raw_len); goto err_iounmap;
}
sysfs_bin_attr_init(&sec->bin_attr); sysfs_bin_attr_init(&sec->bin_attr);
sec->bin_attr.attr.name = sec->raw_name; sec->bin_attr.attr.name = sec->raw_name;
...@@ -212,14 +212,14 @@ static int vpd_section_init(const char *name, struct vpd_section *sec, ...@@ -212,14 +212,14 @@ static int vpd_section_init(const char *name, struct vpd_section *sec,
sec->bin_attr.read = vpd_section_read; sec->bin_attr.read = vpd_section_read;
sec->bin_attr.private = sec; sec->bin_attr.private = sec;
ret = sysfs_create_bin_file(vpd_kobj, &sec->bin_attr); err = sysfs_create_bin_file(vpd_kobj, &sec->bin_attr);
if (ret) if (err)
goto free_sec; goto err_free_raw_name;
sec->kobj = kobject_create_and_add(name, vpd_kobj); sec->kobj = kobject_create_and_add(name, vpd_kobj);
if (!sec->kobj) { if (!sec->kobj) {
ret = -EINVAL; err = -EINVAL;
goto sysfs_remove; goto err_sysfs_remove;
} }
INIT_LIST_HEAD(&sec->attribs); INIT_LIST_HEAD(&sec->attribs);
...@@ -229,14 +229,13 @@ static int vpd_section_init(const char *name, struct vpd_section *sec, ...@@ -229,14 +229,13 @@ static int vpd_section_init(const char *name, struct vpd_section *sec,
return 0; return 0;
sysfs_remove: err_sysfs_remove:
sysfs_remove_bin_file(vpd_kobj, &sec->bin_attr); sysfs_remove_bin_file(vpd_kobj, &sec->bin_attr);
err_free_raw_name:
free_sec:
kfree(sec->raw_name); kfree(sec->raw_name);
err_iounmap:
iounmap(sec->baseaddr); iounmap(sec->baseaddr);
return err;
return ret;
} }
static int vpd_section_destroy(struct vpd_section *sec) static int vpd_section_destroy(struct vpd_section *sec)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment