public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 3/3 v2] firmware: Factor out code to add paths to the firmware path list
Date: Tue, 23 Oct 2012 13:52:56 +0100	[thread overview]
Message-ID: <1350996776-17864-4-git-send-email-dp@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1350996776-17864-1-git-send-email-dp@opensource.wolfsonmicro.com>

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
---
 drivers/base/firmware_class.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 322fff3..cf4aa5f 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -1426,6 +1426,22 @@ static int fw_cache_piggyback_on_request(const char *name)
 }
 #endif
 
+static int fw_add_path_to_list(const char *path)
+{
+	struct fw_path_rec *fwp;
+
+	fwp = kmalloc(sizeof(*fwp), GFP_KERNEL);
+	if (!fwp)
+		return -ENOMEM;
+	fwp->name = kstrdup(path, GFP_KERNEL);
+	if (!fwp->name) {
+		kfree(fwp);
+		return -ENOMEM;
+	}
+	list_add_tail(&fwp->list, &fw_path_list);
+	return 0;
+}
+
 static void fw_free_path_list(void)
 {
 	struct fw_path_rec *fwp;
@@ -1443,7 +1459,7 @@ static void fw_free_path_list(void)
 static int fw_populate_path_list(void)
 {
 	int i;
-	struct fw_path_rec *fwp;
+	int ret;
 	static const char *fw_path[] = {
 		"/lib/firmware/updates/" UTS_RELEASE,
 		"/lib/firmware/updates",
@@ -1452,22 +1468,14 @@ static int fw_populate_path_list(void)
 	};
 
 	for (i = 0; i < ARRAY_SIZE(fw_path); i++) {
-		fwp = kmalloc(sizeof(*fwp), GFP_KERNEL);
-		if (!fwp)
-			goto err_fwp_alloc;
-		fwp->name = kstrdup(fw_path[i], GFP_KERNEL);
-		if (!fwp->name)
-			goto err_fwp_name_alloc;
-		list_add_tail(&fwp->list, &fw_path_list);
+		ret = fw_add_path_to_list(fw_path[i]);
+		if (ret < 0) {
+			fw_free_path_list();
+			return ret;
+		}
 	}
 
 	return 0;
-
-err_fwp_name_alloc:
-	kfree(fwp);
-err_fwp_alloc:
-	fw_free_path_list();
-	return -ENOMEM;
 }
 
 static void *fw_path_seq_start(struct seq_file *seq, loff_t *pos)
-- 
1.8.0


      parent reply	other threads:[~2012-10-23 12:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-23 12:52 [PATCH 0/3 v2] Expose firmware paths via procfs Dimitris Papastamos
2012-10-23 12:52 ` [PATCH 1/3 v2] firmware: Convert firmware path setup from an array to a list Dimitris Papastamos
2012-10-23 13:08   ` Ming Lei
2012-10-23 13:29     ` Dimitris Papastamos
2012-10-23 13:37       ` Ming Lei
2012-10-23 13:44         ` Dimitris Papastamos
2012-10-23 14:37           ` Ming Lei
2012-10-23 12:52 ` [PATCH 2/3 v2] firmware: Add /proc/firmware_path entry to list the firmware paths Dimitris Papastamos
2012-10-25 18:48   ` Greg Kroah-Hartman
2012-10-26 10:07     ` Dimitris Papastamos
2012-10-26 23:56       ` Greg Kroah-Hartman
2012-10-23 12:52 ` Dimitris Papastamos [this message]

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=1350996776-17864-4-git-send-email-dp@opensource.wolfsonmicro.com \
    --to=dp@opensource.wolfsonmicro.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /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