[PATCH 3/3 v2] firmware: Factor out code to add paths to the firmware path list

From: Dimitris Papastamos
Date: Tue Oct 23 2012 - 08:54:49 EST


Signed-off-by: Dimitris Papastamos <dp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/