From c88ec5adb1d9e1e29ca0cbc3ee5046caab492c11 Mon Sep 17 00:00:00 2001 From: Andrew Morton <akpm@osdl.org> Date: Wed, 25 Feb 2004 16:24:38 -0800 Subject: [PATCH] [PATCH] request_firmware(): refactor fw_setup_class_device() From: Manuel Estrada Sainz <ranty@ranty.pantax.net> Based on patch and suggestions from Dmitry Torokhov - Refactor fw_setup_class_device for readability and maintainability. --- drivers/base/firmware_class.c | 37 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 66a5a00617bc..b49476043578 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -278,11 +278,12 @@ fw_setup_class_device_id(struct class_device *class_dev, struct device *dev) /* XXX warning we should watch out for name collisions */ strlcpy(class_dev->class_id, dev->bus_id, BUS_ID_SIZE); } + static int -fw_setup_class_device(struct firmware *fw, struct class_device **class_dev_p, - const char *fw_name, struct device *device) +fw_register_class_device(struct class_device **class_dev_p, + const char *fw_name, struct device *device) { - int retval = 0; + int retval; struct firmware_priv *fw_priv = kmalloc(sizeof (struct firmware_priv), GFP_KERNEL); struct class_device *class_dev = kmalloc(sizeof (struct class_device), @@ -301,13 +302,13 @@ fw_setup_class_device(struct firmware *fw, struct class_device **class_dev_p, init_completion(&fw_priv->completion); fw_priv->attr_data = firmware_attr_data_tmpl; strlcpy(fw_priv->fw_id, fw_name, FIRMWARE_NAME_MAX); - fw_setup_class_device_id(class_dev, device); - class_dev->dev = device; fw_priv->timeout.function = firmware_class_timeout; fw_priv->timeout.data = (u_long) fw_priv; init_timer(&fw_priv->timeout); + fw_setup_class_device_id(class_dev, device); + class_dev->dev = device; class_dev->class = &firmware_class; class_set_devdata(class_dev, fw_priv); retval = class_device_register(class_dev); @@ -316,7 +317,28 @@ fw_setup_class_device(struct firmware *fw, struct class_device **class_dev_p, __FUNCTION__); goto error_kfree; } + *class_dev_p = class_dev; + return 0; +error_kfree: + kfree(fw_priv); + kfree(class_dev); + return retval; +} +static int +fw_setup_class_device(struct firmware *fw, struct class_device **class_dev_p, + const char *fw_name, struct device *device) +{ + struct class_device *class_dev; + struct firmware_priv *fw_priv; + int retval; + + *class_dev_p = NULL; + retval = fw_register_class_device(&class_dev, fw_name, device); + if (retval) + goto out; + + fw_priv = class_get_devdata(class_dev); fw_priv->fw = fw; retval = sysfs_create_bin_file(&class_dev->kobj, &fw_priv->attr_data); @@ -341,11 +363,6 @@ fw_setup_class_device(struct firmware *fw, struct class_device **class_dev_p, sysfs_remove_bin_file(&class_dev->kobj, &fw_priv->attr_data); error_unreg_class_dev: class_device_unregister(class_dev); - goto out; - -error_kfree: - kfree(fw_priv); - kfree(class_dev); out: return retval; } -- 2.30.9