mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Wei-Ning Huang <wnhuang@google.com>,
	Julius Werner <jwerner@chromium.org>,
	Guenter Roeck <groeck@chromium.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 5/8] firmware: vpd: use kasprintf() when forming name of 'raw' attribute
Date: Tue, 23 May 2017 17:07:45 -0700	[thread overview]
Message-ID: <20170524000748.39310-5-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20170524000748.39310-1-dmitry.torokhov@gmail.com>

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: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/firmware/google/vpd.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
index cb07a2984ece..3463b8037ed8 100644
--- a/drivers/firmware/google/vpd.c
+++ b/drivers/firmware/google/vpd.c
@@ -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,
 			    phys_addr_t physaddr, size_t size)
 {
-	int ret;
-	int raw_len;
+	int err;
 
 	sec->baseaddr = memremap(physaddr, size, MEMREMAP_WB);
 	if (!sec->baseaddr)
@@ -200,10 +199,11 @@ static int vpd_section_init(const char *name, struct vpd_section *sec,
 	sec->name = name;
 
 	/* We want to export the raw partion with name ${name}_raw */
-	raw_len = strlen(name) + 5;
-	sec->raw_name = kzalloc(raw_len, GFP_KERNEL);
-	strncpy(sec->raw_name, name, raw_len);
-	strncat(sec->raw_name, "_raw", raw_len);
+	sec->raw_name = kasprintf(GFP_KERNEL, "%s_raw", name);
+	if (!sec->raw_name) {
+		err = -ENOMEM;
+		goto err_iounmap;
+	}
 
 	sysfs_bin_attr_init(&sec->bin_attr);
 	sec->bin_attr.attr.name = sec->raw_name;
@@ -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.private = sec;
 
-	ret = sysfs_create_bin_file(vpd_kobj, &sec->bin_attr);
-	if (ret)
-		goto free_sec;
+	err = sysfs_create_bin_file(vpd_kobj, &sec->bin_attr);
+	if (err)
+		goto err_free_raw_name;
 
 	sec->kobj = kobject_create_and_add(name, vpd_kobj);
 	if (!sec->kobj) {
-		ret = -EINVAL;
-		goto sysfs_remove;
+		err = -EINVAL;
+		goto err_sysfs_remove;
 	}
 
 	INIT_LIST_HEAD(&sec->attribs);
@@ -229,14 +229,13 @@ static int vpd_section_init(const char *name, struct vpd_section *sec,
 
 	return 0;
 
-sysfs_remove:
+err_sysfs_remove:
 	sysfs_remove_bin_file(vpd_kobj, &sec->bin_attr);
-
-free_sec:
+err_free_raw_name:
 	kfree(sec->raw_name);
+err_iounmap:
 	iounmap(sec->baseaddr);
-
-	return ret;
+	return err;
 }
 
 static int vpd_section_destroy(struct vpd_section *sec)
-- 
2.13.0.219.gdb65acc882-goog

  parent reply	other threads:[~2017-05-24  0:08 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24  0:07 [PATCH 1/8] firmware: vpd: do not leave freed section attributes to the list Dmitry Torokhov
2017-05-24  0:07 ` [PATCH 2/8] firmware: vpd: use kdtrndup when copying section key Dmitry Torokhov
2017-05-24 17:13   ` Guenter Roeck
2017-05-24  0:07 ` [PATCH 3/8] firmware: vpd: avoid potential use-after-free when destroying section Dmitry Torokhov
2017-05-24 17:15   ` Guenter Roeck
2017-05-24  0:07 ` [PATCH 4/8] firmware: vpd: do not leak kobjects Dmitry Torokhov
2017-05-24 17:16   ` Guenter Roeck
2017-05-24  0:07 ` Dmitry Torokhov [this message]
2017-05-24 17:18   ` [PATCH 5/8] firmware: vpd: use kasprintf() when forming name of 'raw' attribute Guenter Roeck
2017-05-24  0:07 ` [PATCH 6/8] firmware: vpd: do not clear statically allocated data Dmitry Torokhov
2017-05-24 17:19   ` Guenter Roeck
2017-05-24  0:07 ` [PATCH 7/8] firmware: vpd: remove platform driver Dmitry Torokhov
2017-05-24 17:22   ` Guenter Roeck
2017-05-25  0:04     ` Julius Werner
2017-05-25  2:38       ` Dmitry Torokhov
2017-05-24  0:07 ` [PATCH 8/8] firmware: vpd: fix confusion between memremap and iounmap Dmitry Torokhov
2017-05-24 17:23   ` Guenter Roeck
2017-05-25 13:41   ` Greg Kroah-Hartman
2017-05-24 17:13 ` [PATCH 1/8] firmware: vpd: do not leave freed section attributes to the list Guenter Roeck
2017-05-25 13:40 ` Greg Kroah-Hartman
2017-05-25 16:35   ` Dmitry Torokhov
2017-05-25 16:50     ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170524000748.39310-5-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=groeck@chromium.org \
    --cc=jwerner@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wnhuang@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome