From 31c3dc7488f2564fc398d5a416726031f56d6343 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Tue, 23 Oct 2012 05:18:21 -0700 Subject: leds: leds-ns2: use gpio_request_one Using gpio_request_one can make the code simpler because it can set the direction and initial value in one shot. Signed-off-by: Jingoo Han Signed-off-by: Bryan Wu --- drivers/leds/leds-ns2.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'drivers/leds/leds-ns2.c') diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c index d176ec83f5d9..ae8f93b3364e 100644 --- a/drivers/leds/leds-ns2.c +++ b/drivers/leds/leds-ns2.c @@ -191,25 +191,18 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat, int ret; enum ns2_led_modes mode; - ret = gpio_request(template->cmd, template->name); - if (ret == 0) { - ret = gpio_direction_output(template->cmd, - gpio_get_value(template->cmd)); - if (ret) - gpio_free(template->cmd); - } + ret = gpio_request_one(template->cmd, + GPIOF_DIR_OUT | gpio_get_value(template->cmd), + template->name); if (ret) { dev_err(&pdev->dev, "%s: failed to setup command GPIO\n", template->name); + return ret; } - ret = gpio_request(template->slow, template->name); - if (ret == 0) { - ret = gpio_direction_output(template->slow, - gpio_get_value(template->slow)); - if (ret) - gpio_free(template->slow); - } + ret = gpio_request_one(template->slow, + GPIOF_DIR_OUT | gpio_get_value(template->slow), + template->name); if (ret) { dev_err(&pdev->dev, "%s: failed to setup slow GPIO\n", template->name); -- cgit v1.2.3-58-ga151 From 3874350c598d7796a6dd2da111247be88e56d002 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Tue, 23 Oct 2012 05:25:35 -0700 Subject: leds: leds-ns2: replace strict_strtoul() with kstrtoul() The usage of strict_strtoul() is not preferred, because strict_strtoul() is obsolete. Thus, kstrtoul() should be used. Signed-off-by: Jingoo Han Signed-off-by: Bryan Wu --- drivers/leds/leds-ns2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/leds/leds-ns2.c') diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c index ae8f93b3364e..5df2a250a13e 100644 --- a/drivers/leds/leds-ns2.c +++ b/drivers/leds/leds-ns2.c @@ -149,7 +149,7 @@ static ssize_t ns2_led_sata_store(struct device *dev, unsigned long enable; enum ns2_led_modes mode; - ret = strict_strtoul(buff, 10, &enable); + ret = kstrtoul(buff, 10, &enable); if (ret < 0) return ret; -- cgit v1.2.3-58-ga151 From 04195823aa16d648cd7f52abd2ea6df1b9aee53f Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Sun, 25 Nov 2012 10:28:10 +0530 Subject: leds: leds-ns2: use devm_gpio_request_one devm_gpio_request_one is device managed and makes error handling and cleanup simpler. Cc: Simon Guinot Signed-off-by: Sachin Kamat Signed-off-by: Bryan Wu --- drivers/leds/leds-ns2.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'drivers/leds/leds-ns2.c') diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c index 5df2a250a13e..9505d862a216 100644 --- a/drivers/leds/leds-ns2.c +++ b/drivers/leds/leds-ns2.c @@ -191,7 +191,7 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat, int ret; enum ns2_led_modes mode; - ret = gpio_request_one(template->cmd, + ret = devm_gpio_request_one(&pdev->dev, template->cmd, GPIOF_DIR_OUT | gpio_get_value(template->cmd), template->name); if (ret) { @@ -200,13 +200,13 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat, return ret; } - ret = gpio_request_one(template->slow, + ret = devm_gpio_request_one(&pdev->dev, template->slow, GPIOF_DIR_OUT | gpio_get_value(template->slow), template->name); if (ret) { dev_err(&pdev->dev, "%s: failed to setup slow GPIO\n", template->name); - goto err_free_cmd; + return ret; } rwlock_init(&led_dat->rw_lock); @@ -221,7 +221,7 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat, ret = ns2_led_get_mode(led_dat, &mode); if (ret < 0) - goto err_free_slow; + return ret; /* Set LED initial state. */ led_dat->sata = (mode == NS_V2_LED_SATA) ? 1 : 0; @@ -230,7 +230,7 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat, ret = led_classdev_register(&pdev->dev, &led_dat->cdev); if (ret < 0) - goto err_free_slow; + return ret; ret = device_create_file(led_dat->cdev.dev, &dev_attr_sata); if (ret < 0) @@ -240,11 +240,6 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat, err_free_cdev: led_classdev_unregister(&led_dat->cdev); -err_free_slow: - gpio_free(led_dat->slow); -err_free_cmd: - gpio_free(led_dat->cmd); - return ret; } @@ -252,8 +247,6 @@ static void delete_ns2_led(struct ns2_led_data *led_dat) { device_remove_file(led_dat->cdev.dev, &dev_attr_sata); led_classdev_unregister(&led_dat->cdev); - gpio_free(led_dat->cmd); - gpio_free(led_dat->slow); } static int __devinit ns2_led_probe(struct platform_device *pdev) -- cgit v1.2.3-58-ga151