linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fbdev: omapfb: Use sysfs_emit_at() to simplify code
@ 2024-08-08 12:14 Christophe JAILLET
  2024-08-08 13:15 ` Andi Shyti
  2024-08-28 18:08 ` Helge Deller
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2024-08-08 12:14 UTC (permalink / raw)
  To: Helge Deller
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-fbdev,
	linux-omap, dri-devel

This file already uses sysfs_emit(). So be consistent and also use
sysfs_emit_at().

Moreover, size is always < PAGE_SIZE because scnprintf() (and now
sysfs_emit_at()) returns the number of characters written not including the
trailing '\0'. So some tests can be removed.

This slightly simplifies the code and makes it more readable.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only.

2 spaces are added before color_caps[i].name and color_caps[i].name, but
not ctrl_caps[i].name.
I wonder if it is done on purpose or if it could be removed as well.
---
 drivers/video/fbdev/omap/omapfb_main.c | 36 ++++++++++----------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
index aa31c0d26e92..e12c6019a4d6 100644
--- a/drivers/video/fbdev/omap/omapfb_main.c
+++ b/drivers/video/fbdev/omap/omapfb_main.c
@@ -1241,14 +1241,13 @@ static ssize_t omapfb_show_caps_num(struct device *dev,
 {
 	struct omapfb_device *fbdev = dev_get_drvdata(dev);
 	int plane;
-	size_t size;
+	size_t size = 0;
 	struct omapfb_caps caps;
 
 	plane = 0;
-	size = 0;
-	while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
+	while (plane < OMAPFB_PLANE_NUM) {
 		omapfb_get_caps(fbdev, plane, &caps);
-		size += scnprintf(&buf[size], PAGE_SIZE - size,
+		size += sysfs_emit_at(buf, size,
 			"plane#%d %#010x %#010x %#010x\n",
 			plane, caps.ctrl, caps.plane_color, caps.wnd_color);
 		plane++;
@@ -1263,34 +1262,27 @@ static ssize_t omapfb_show_caps_text(struct device *dev,
 	int i;
 	struct omapfb_caps caps;
 	int plane;
-	size_t size;
+	size_t size = 0;
 
 	plane = 0;
-	size = 0;
-	while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
+	while (plane < OMAPFB_PLANE_NUM) {
 		omapfb_get_caps(fbdev, plane, &caps);
-		size += scnprintf(&buf[size], PAGE_SIZE - size,
-				 "plane#%d:\n", plane);
-		for (i = 0; i < ARRAY_SIZE(ctrl_caps) &&
-		     size < PAGE_SIZE; i++) {
+		size += sysfs_emit_at(buf, size, "plane#%d:\n", plane);
+		for (i = 0; i < ARRAY_SIZE(ctrl_caps); i++) {
 			if (ctrl_caps[i].flag & caps.ctrl)
-				size += scnprintf(&buf[size], PAGE_SIZE - size,
+				size += sysfs_emit_at(buf, size,
 					" %s\n", ctrl_caps[i].name);
 		}
-		size += scnprintf(&buf[size], PAGE_SIZE - size,
-				 " plane colors:\n");
-		for (i = 0; i < ARRAY_SIZE(color_caps) &&
-		     size < PAGE_SIZE; i++) {
+		size += sysfs_emit_at(buf, size, " plane colors:\n");
+		for (i = 0; i < ARRAY_SIZE(color_caps); i++) {
 			if (color_caps[i].flag & caps.plane_color)
-				size += scnprintf(&buf[size], PAGE_SIZE - size,
+				size += sysfs_emit_at(buf, size,
 					"  %s\n", color_caps[i].name);
 		}
-		size += scnprintf(&buf[size], PAGE_SIZE - size,
-				 " window colors:\n");
-		for (i = 0; i < ARRAY_SIZE(color_caps) &&
-		     size < PAGE_SIZE; i++) {
+		size += sysfs_emit_at(buf, size, " window colors:\n");
+		for (i = 0; i < ARRAY_SIZE(color_caps); i++) {
 			if (color_caps[i].flag & caps.wnd_color)
-				size += scnprintf(&buf[size], PAGE_SIZE - size,
+				size += sysfs_emit_at(buf, size,
 					"  %s\n", color_caps[i].name);
 		}
 
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fbdev: omapfb: Use sysfs_emit_at() to simplify code
  2024-08-08 12:14 [PATCH] fbdev: omapfb: Use sysfs_emit_at() to simplify code Christophe JAILLET
@ 2024-08-08 13:15 ` Andi Shyti
  2024-08-28 18:08 ` Helge Deller
  1 sibling, 0 replies; 3+ messages in thread
From: Andi Shyti @ 2024-08-08 13:15 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Helge Deller, linux-kernel, kernel-janitors, linux-fbdev,
	linux-omap, dri-devel

Hi Christophe,

On Thu, Aug 08, 2024 at 02:14:22PM +0200, Christophe JAILLET wrote:
> This file already uses sysfs_emit(). So be consistent and also use
> sysfs_emit_at().
> 
> Moreover, size is always < PAGE_SIZE because scnprintf() (and now
> sysfs_emit_at()) returns the number of characters written not including the
> trailing '\0'. So some tests can be removed.
> 
> This slightly simplifies the code and makes it more readable.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>

Thanks,
Andi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fbdev: omapfb: Use sysfs_emit_at() to simplify code
  2024-08-08 12:14 [PATCH] fbdev: omapfb: Use sysfs_emit_at() to simplify code Christophe JAILLET
  2024-08-08 13:15 ` Andi Shyti
@ 2024-08-28 18:08 ` Helge Deller
  1 sibling, 0 replies; 3+ messages in thread
From: Helge Deller @ 2024-08-28 18:08 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: linux-kernel, kernel-janitors, linux-fbdev, linux-omap, dri-devel

On 8/8/24 14:14, Christophe JAILLET wrote:
> This file already uses sysfs_emit(). So be consistent and also use
> sysfs_emit_at().
>
> Moreover, size is always < PAGE_SIZE because scnprintf() (and now
> sysfs_emit_at()) returns the number of characters written not including the
> trailing '\0'. So some tests can be removed.
>
> This slightly simplifies the code and makes it more readable.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only.
>
> 2 spaces are added before color_caps[i].name and color_caps[i].name, but
> not ctrl_caps[i].name.
> I wonder if it is done on purpose or if it could be removed as well.
> ---
>   drivers/video/fbdev/omap/omapfb_main.c | 36 ++++++++++----------------
>   1 file changed, 14 insertions(+), 22 deletions(-)

applied.

Thanks!
Helge


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-28 18:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08 12:14 [PATCH] fbdev: omapfb: Use sysfs_emit_at() to simplify code Christophe JAILLET
2024-08-08 13:15 ` Andi Shyti
2024-08-28 18:08 ` Helge Deller

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).