[v2,1/2] leds: trigger: pattern: minor code style changes

Message ID 20221121123833.164614-2-mmkurbanov@sberdevices.ru
State New
Headers
Series leds: trigger: pattern: notify usespace if pattern finished |

Commit Message

Martin Kurbanov Nov. 21, 2022, 12:38 p.m. UTC
  This patch adds some minor code style changes:
    - remove a blank line before DEVICE_ATTR_RW declarations
    - convert sysfs scnprintf() to sysfs_emit()/sysfs_emit_at()
    - use module_led_trigger instead of pattern_trig_init/exit

Signed-off-by: Martin Kurbanov <mmkurbanov@sberdevices.ru>
---
 drivers/leds/trigger/ledtrig-pattern.c | 29 +++++++-------------------
 1 file changed, 7 insertions(+), 22 deletions(-)
  

Comments

Andy Shevchenko Nov. 21, 2022, 1:28 p.m. UTC | #1
On Mon, Nov 21, 2022 at 2:39 PM Martin Kurbanov
<mmkurbanov@sberdevices.ru> wrote:
>
> This patch adds some minor code style changes:
>     - remove a blank line before DEVICE_ATTR_RW declarations
>     - convert sysfs scnprintf() to sysfs_emit()/sysfs_emit_at()
>     - use module_led_trigger instead of pattern_trig_init/exit
>
> Signed-off-by: Martin Kurbanov <mmkurbanov@sberdevices.ru>

...

> +               count += sysfs_emit_at(buf, count,
> +                                      "%d %u ",

With this getting shorter you may put these to one line.

> +                                      data->patterns[i].brightness,
> +                                      data->patterns[i].delta_t);

...

> -static int __init pattern_trig_init(void)
> -{
> -       return led_trigger_register(&pattern_led_trigger);
> -}
> -
> -static void __exit pattern_trig_exit(void)
> -{
> -       led_trigger_unregister(&pattern_led_trigger);
> -}
> -
> -module_init(pattern_trig_init);
> -module_exit(pattern_trig_exit);
> +module_led_trigger(pattern_led_trigger);

This should be a separate patch.

...

Otherwise this looks good to me.
  

Patch

diff --git a/drivers/leds/trigger/ledtrig-pattern.c b/drivers/leds/trigger/ledtrig-pattern.c
index 43a265dc4696..354304b404aa 100644
--- a/drivers/leds/trigger/ledtrig-pattern.c
+++ b/drivers/leds/trigger/ledtrig-pattern.c
@@ -155,7 +155,7 @@  static ssize_t repeat_show(struct device *dev, struct device_attribute *attr,
 
 	mutex_unlock(&data->lock);
 
-	return scnprintf(buf, PAGE_SIZE, "%d\n", repeat);
+	return sysfs_emit(buf, "%d\n", repeat);
 }
 
 static ssize_t repeat_store(struct device *dev, struct device_attribute *attr,
@@ -192,7 +192,6 @@  static ssize_t repeat_store(struct device *dev, struct device_attribute *attr,
 	mutex_unlock(&data->lock);
 	return err < 0 ? err : count;
 }
-
 static DEVICE_ATTR_RW(repeat);
 
 static ssize_t pattern_trig_show_patterns(struct pattern_trig_data *data,
@@ -207,13 +206,13 @@  static ssize_t pattern_trig_show_patterns(struct pattern_trig_data *data,
 		goto out;
 
 	for (i = 0; i < data->npatterns; i++) {
-		count += scnprintf(buf + count, PAGE_SIZE - count,
-				   "%d %u ",
-				   data->patterns[i].brightness,
-				   data->patterns[i].delta_t);
+		count += sysfs_emit_at(buf, count,
+				       "%d %u ",
+				       data->patterns[i].brightness,
+				       data->patterns[i].delta_t);
 	}
 
-	buf[count - 1] = '\n';
+	sysfs_emit_at(buf, count - 1, "\n");
 
 out:
 	mutex_unlock(&data->lock);
@@ -307,7 +306,6 @@  static ssize_t pattern_store(struct device *dev, struct device_attribute *attr,
 
 	return pattern_trig_store_patterns(led_cdev, buf, NULL, count, false);
 }
-
 static DEVICE_ATTR_RW(pattern);
 
 static ssize_t hw_pattern_show(struct device *dev,
@@ -327,7 +325,6 @@  static ssize_t hw_pattern_store(struct device *dev,
 
 	return pattern_trig_store_patterns(led_cdev, buf, NULL, count, true);
 }
-
 static DEVICE_ATTR_RW(hw_pattern);
 
 static umode_t pattern_trig_attrs_mode(struct kobject *kobj,
@@ -443,19 +440,7 @@  static struct led_trigger pattern_led_trigger = {
 	.deactivate = pattern_trig_deactivate,
 	.groups = pattern_trig_groups,
 };
-
-static int __init pattern_trig_init(void)
-{
-	return led_trigger_register(&pattern_led_trigger);
-}
-
-static void __exit pattern_trig_exit(void)
-{
-	led_trigger_unregister(&pattern_led_trigger);
-}
-
-module_init(pattern_trig_init);
-module_exit(pattern_trig_exit);
+module_led_trigger(pattern_led_trigger);
 
 MODULE_AUTHOR("Raphael Teysseyre <rteysseyre@gmail.com>");
 MODULE_AUTHOR("Baolin Wang <baolin.wang@linaro.org>");