linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Pavel Machek <pavel@ucw.cz>, Lee Jones <lee@kernel.org>,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Christian Marangi <ansuelsmth@gmail.com>
Subject: [PATCH 1/3] leds: leds-lp5569: Convert to sysfs_emit API
Date: Thu, 27 Jun 2024 00:15:11 +0200	[thread overview]
Message-ID: <20240626221520.2846-1-ansuelsmth@gmail.com> (raw)

Convert sprintf to the much safer sysfs_emit API to handle output for
sysfs.

Also better handle situation where on the same chip there may be LED
open and shorted at the same time.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/leds/leds-lp5569.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/leds-lp5569.c b/drivers/leds/leds-lp5569.c
index 7ccd8dd6026a..e5e7e61c8916 100644
--- a/drivers/leds/leds-lp5569.c
+++ b/drivers/leds/leds-lp5569.c
@@ -268,8 +268,8 @@ static ssize_t lp5569_led_open_test(struct lp55xx_led *led, char *buf)
 	led_tmp = led;
 	for (i = 0; i < pdata->num_channels; i++) {
 		if (leds_fault[led_tmp->chan_nr])
-			pos += sprintf(buf + pos, "LED %d OPEN FAIL\n",
-				       led_tmp->chan_nr);
+			pos += sysfs_emit_at(buf, pos, "LED %d OPEN FAIL\n",
+					     led_tmp->chan_nr);
 
 		led_tmp++;
 	}
@@ -366,8 +366,8 @@ static ssize_t lp5569_led_short_test(struct lp55xx_led *led, char *buf)
 	led_tmp = led;
 	for (i = 0; i < pdata->num_channels; i++) {
 		if (leds_fault[led_tmp->chan_nr])
-			pos += sprintf(buf + pos, "LED %d SHORTED FAIL\n",
-				       led_tmp->chan_nr);
+			pos += sysfs_emit_at(buf, pos, "LED %d SHORTED FAIL\n",
+					     led_tmp->chan_nr);
 
 		led_tmp++;
 	}
@@ -404,7 +404,7 @@ static ssize_t lp5569_selftest(struct device *dev,
 		goto fail;
 
 	/* Test LED Shorted */
-	pos = lp5569_led_short_test(led, buf);
+	pos += lp5569_led_short_test(led, buf);
 	if (pos < 0)
 		goto fail;
 
@@ -420,10 +420,10 @@ static ssize_t lp5569_selftest(struct device *dev,
 	}
 
 	if (pos == 0)
-		pos = sprintf(buf, "OK\n");
+		pos = sysfs_emit(buf, "OK\n");
 	goto release_lock;
 fail:
-	pos = sprintf(buf, "FAIL\n");
+	pos = sysfs_emit(buf, "FAIL\n");
 
 release_lock:
 	mutex_unlock(&chip->lock);
-- 
2.45.1


             reply	other threads:[~2024-06-26 22:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-26 22:15 Christian Marangi [this message]
2024-06-26 22:15 ` [PATCH 2/3] leds: leds-lp5523: Convert to sysfs_emit API Christian Marangi
2024-06-26 22:15 ` [PATCH 3/3] leds: leds-lp55xx: Convert mutex lock/unlock to guard API Christian Marangi
2024-06-27  5:52   ` Markus Elfring
2024-06-27  7:08     ` Lee Jones
2024-06-27  7:09     ` Lee Jones
2024-06-27  8:12       ` [3/3] " Markus Elfring
2024-06-27  8:22         ` Lee Jones
2024-06-27  9:24           ` Markus Elfring
2024-07-10  7:10   ` [PATCH 3/3] " Lee Jones
2024-07-10 16:24   ` Markus Elfring
2024-07-10 16:55     ` Lee Jones
2024-07-10 10:29       ` Christian Marangi
2024-07-10 18:10         ` [3/3] " Markus Elfring
2024-07-11  8:08           ` Lee Jones
2024-07-11  8:05         ` [PATCH 3/3] " Lee Jones
2024-07-04 15:44 ` [PATCH 1/3] leds: leds-lp5569: Convert to sysfs_emit API Lee Jones

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=20240626221520.2846-1-ansuelsmth@gmail.com \
    --to=ansuelsmth@gmail.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /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;
as well as URLs for NNTP newsgroup(s).