* [PATCH] fbdev: omapfb: panel-sony-acx565akm: Simplify show_cabc_available_modes()
@ 2024-08-08 9:46 Christophe JAILLET
2024-08-08 10:25 ` Andi Shyti
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Christophe JAILLET @ 2024-08-08 9:46 UTC (permalink / raw)
To: Helge Deller
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-omap,
linux-fbdev, dri-devel
Use sysfs_emit_at() instead of snprintf() + custom logic.
Using sysfs_emit_at() is much more simple.
Also, sysfs_emit() is already used in this function, so using
sysfs_emit_at() is more consistent.
Also simplify the logic:
- always add a space after an entry
- change the last space into a '\n'
Finally it is easy to see that, given the size of cabc_modes, PAGE_SIZE
can not be reached.
So better keep everything simple (and correct).
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
.../omap2/omapfb/displays/panel-sony-acx565akm.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
index 71d2e015960c..fc975615d5c9 100644
--- a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
+++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
@@ -466,19 +466,20 @@ static ssize_t show_cabc_available_modes(struct device *dev,
char *buf)
{
struct panel_drv_data *ddata = dev_get_drvdata(dev);
- int len;
+ int len = 0;
int i;
if (!ddata->has_cabc)
return sysfs_emit(buf, "%s\n", cabc_modes[0]);
- for (i = 0, len = 0;
- len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
- len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
- i ? " " : "", cabc_modes[i],
- i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
+ for (i = 0; i < ARRAY_SIZE(cabc_modes); i++)
+ len += sysfs_emit_at(buf, len, "%s ", cabc_modes[i]);
+
+ /* Remove the trailing space */
+ if (len)
+ buf[len - 1] = '\n';
- return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
+ return len;
}
static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
--
2.46.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] fbdev: omapfb: panel-sony-acx565akm: Simplify show_cabc_available_modes()
2024-08-08 9:46 [PATCH] fbdev: omapfb: panel-sony-acx565akm: Simplify show_cabc_available_modes() Christophe JAILLET
@ 2024-08-08 10:25 ` Andi Shyti
2024-08-09 14:42 ` Dan Carpenter
2024-08-28 18:08 ` Helge Deller
2 siblings, 0 replies; 7+ messages in thread
From: Andi Shyti @ 2024-08-08 10:25 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Helge Deller, linux-kernel, kernel-janitors, linux-omap,
linux-fbdev, dri-devel
Hi Christophe,
On Thu, Aug 08, 2024 at 11:46:11AM +0200, Christophe JAILLET wrote:
> Use sysfs_emit_at() instead of snprintf() + custom logic.
> Using sysfs_emit_at() is much more simple.
>
> Also, sysfs_emit() is already used in this function, so using
> sysfs_emit_at() is more consistent.
>
> Also simplify the logic:
> - always add a space after an entry
> - change the last space into a '\n'
>
> Finally it is easy to see that, given the size of cabc_modes, PAGE_SIZE
> can not be reached.
> So better keep everything simple (and correct).
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
neat!
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Andi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] fbdev: omapfb: panel-sony-acx565akm: Simplify show_cabc_available_modes()
2024-08-08 9:46 [PATCH] fbdev: omapfb: panel-sony-acx565akm: Simplify show_cabc_available_modes() Christophe JAILLET
2024-08-08 10:25 ` Andi Shyti
@ 2024-08-09 14:42 ` Dan Carpenter
2024-08-09 14:48 ` Dan Carpenter
2024-08-09 15:09 ` Christophe JAILLET
2024-08-28 18:08 ` Helge Deller
2 siblings, 2 replies; 7+ messages in thread
From: Dan Carpenter @ 2024-08-09 14:42 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Helge Deller, linux-kernel, kernel-janitors, linux-omap,
linux-fbdev, dri-devel
On Thu, Aug 08, 2024 at 11:46:11AM +0200, Christophe JAILLET wrote:
> Use sysfs_emit_at() instead of snprintf() + custom logic.
> Using sysfs_emit_at() is much more simple.
>
> Also, sysfs_emit() is already used in this function, so using
> sysfs_emit_at() is more consistent.
>
> Also simplify the logic:
> - always add a space after an entry
> - change the last space into a '\n'
>
> Finally it is easy to see that, given the size of cabc_modes, PAGE_SIZE
> can not be reached.
> So better keep everything simple (and correct).
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> .../omap2/omapfb/displays/panel-sony-acx565akm.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
> index 71d2e015960c..fc975615d5c9 100644
> --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
> +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
> @@ -466,19 +466,20 @@ static ssize_t show_cabc_available_modes(struct device *dev,
> char *buf)
> {
> struct panel_drv_data *ddata = dev_get_drvdata(dev);
> - int len;
> + int len = 0;
> int i;
>
> if (!ddata->has_cabc)
> return sysfs_emit(buf, "%s\n", cabc_modes[0]);
>
> - for (i = 0, len = 0;
> - len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
> - len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
> - i ? " " : "", cabc_modes[i],
> - i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
> + for (i = 0; i < ARRAY_SIZE(cabc_modes); i++)
> + len += sysfs_emit_at(buf, len, "%s ", cabc_modes[i]);
> +
> + /* Remove the trailing space */
> + if (len)
> + buf[len - 1] = '\n';
I'm uncomfortable with this line. It assumes we don't overflow PAGE_SIZE where
the original code was careful about checking. Probably easiest to do what the
original code did and say:
for (i = 0; i < ARRAY_SIZE(cabc_modes); i++)
len += sysfs_emit_at(buf, len, "%s%s", cabc_modes[i],
i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
regards,
dan carpenter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] fbdev: omapfb: panel-sony-acx565akm: Simplify show_cabc_available_modes()
2024-08-09 14:42 ` Dan Carpenter
@ 2024-08-09 14:48 ` Dan Carpenter
2024-08-09 15:09 ` Christophe JAILLET
1 sibling, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2024-08-09 14:48 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Helge Deller, linux-kernel, kernel-janitors, linux-omap,
linux-fbdev, dri-devel
On Fri, Aug 09, 2024 at 05:42:32PM +0300, Dan Carpenter wrote:
> On Thu, Aug 08, 2024 at 11:46:11AM +0200, Christophe JAILLET wrote:
> > Use sysfs_emit_at() instead of snprintf() + custom logic.
> > Using sysfs_emit_at() is much more simple.
> >
> > Also, sysfs_emit() is already used in this function, so using
> > sysfs_emit_at() is more consistent.
> >
> > Also simplify the logic:
> > - always add a space after an entry
> > - change the last space into a '\n'
> >
> > Finally it is easy to see that, given the size of cabc_modes, PAGE_SIZE
> > can not be reached.
> > So better keep everything simple (and correct).
> >
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > ---
> > .../omap2/omapfb/displays/panel-sony-acx565akm.c | 15 ++++++++-------
> > 1 file changed, 8 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
> > index 71d2e015960c..fc975615d5c9 100644
> > --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
> > +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
> > @@ -466,19 +466,20 @@ static ssize_t show_cabc_available_modes(struct device *dev,
> > char *buf)
> > {
> > struct panel_drv_data *ddata = dev_get_drvdata(dev);
> > - int len;
> > + int len = 0;
> > int i;
> >
> > if (!ddata->has_cabc)
> > return sysfs_emit(buf, "%s\n", cabc_modes[0]);
> >
> > - for (i = 0, len = 0;
> > - len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
> > - len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
> > - i ? " " : "", cabc_modes[i],
> > - i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
> > + for (i = 0; i < ARRAY_SIZE(cabc_modes); i++)
> > + len += sysfs_emit_at(buf, len, "%s ", cabc_modes[i]);
> > +
> > + /* Remove the trailing space */
> > + if (len)
> > + buf[len - 1] = '\n';
>
> I'm uncomfortable with this line. It assumes we don't overflow PAGE_SIZE where
> the original code was careful about checking. Probably easiest to do what the
> original code did and say:
>
> for (i = 0; i < ARRAY_SIZE(cabc_modes); i++)
> len += sysfs_emit_at(buf, len, "%s%s", cabc_modes[i],
> i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
Or you could change it to:
if (len)
sysfs_emit_at(buf, len - 1, "\n");
But that feels weird.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] fbdev: omapfb: panel-sony-acx565akm: Simplify show_cabc_available_modes()
2024-08-09 14:42 ` Dan Carpenter
2024-08-09 14:48 ` Dan Carpenter
@ 2024-08-09 15:09 ` Christophe JAILLET
2024-08-09 15:13 ` Dan Carpenter
1 sibling, 1 reply; 7+ messages in thread
From: Christophe JAILLET @ 2024-08-09 15:09 UTC (permalink / raw)
To: Dan Carpenter
Cc: Helge Deller, linux-kernel, kernel-janitors, linux-omap,
linux-fbdev, dri-devel
Le 09/08/2024 à 16:42, Dan Carpenter a écrit :
> On Thu, Aug 08, 2024 at 11:46:11AM +0200, Christophe JAILLET wrote:
>> Use sysfs_emit_at() instead of snprintf() + custom logic.
>> Using sysfs_emit_at() is much more simple.
>>
>> Also, sysfs_emit() is already used in this function, so using
>> sysfs_emit_at() is more consistent.
>>
>> Also simplify the logic:
>> - always add a space after an entry
>> - change the last space into a '\n'
>>
>> Finally it is easy to see that, given the size of cabc_modes, PAGE_SIZE
>> can not be reached.
>> So better keep everything simple (and correct).
>>
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> .../omap2/omapfb/displays/panel-sony-acx565akm.c | 15 ++++++++-------
>> 1 file changed, 8 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
>> index 71d2e015960c..fc975615d5c9 100644
>> --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
>> +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
>> @@ -466,19 +466,20 @@ static ssize_t show_cabc_available_modes(struct device *dev,
>> char *buf)
>> {
>> struct panel_drv_data *ddata = dev_get_drvdata(dev);
>> - int len;
>> + int len = 0;
>> int i;
>>
>> if (!ddata->has_cabc)
>> return sysfs_emit(buf, "%s\n", cabc_modes[0]);
>>
>> - for (i = 0, len = 0;
>> - len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
>> - len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
>> - i ? " " : "", cabc_modes[i],
>> - i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
>> + for (i = 0; i < ARRAY_SIZE(cabc_modes); i++)
>> + len += sysfs_emit_at(buf, len, "%s ", cabc_modes[i]);
>> +
>> + /* Remove the trailing space */
>> + if (len)
>> + buf[len - 1] = '\n';
>
> I'm uncomfortable with this line. It assumes we don't overflow PAGE_SIZE where
> the original code was careful about checking. Probably easiest to do what the
> original code did and say:
>
Hi Dan,
I don't follow you. AFAIK, it does not assume anything.
Thanks to sysfs_emit_at(), len can only be in [0..PAGE_SIZE-1] because
the trailing \0 is not counted.
So, as len != 0, len-1 is in [0..PAGE_SIZE-2].
How do you think an overflow could happen?
Also, all this code does is buildind:
"off, ui, still-image, moving-image\n"
So in any case, an overflow is impossible, and really unlikely in the
future as well.
From my PoV, my proposed patch is both much more readable and still
correct in all cases.
CJ
> for (i = 0; i < ARRAY_SIZE(cabc_modes); i++)
> len += sysfs_emit_at(buf, len, "%s%s", cabc_modes[i],
> i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
>
> regards,
> dan carpenter
>
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] fbdev: omapfb: panel-sony-acx565akm: Simplify show_cabc_available_modes()
2024-08-09 15:09 ` Christophe JAILLET
@ 2024-08-09 15:13 ` Dan Carpenter
0 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2024-08-09 15:13 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Helge Deller, linux-kernel, kernel-janitors, linux-omap,
linux-fbdev, dri-devel
On Fri, Aug 09, 2024 at 05:09:28PM +0200, Christophe JAILLET wrote:
> Le 09/08/2024 à 16:42, Dan Carpenter a écrit :
> > On Thu, Aug 08, 2024 at 11:46:11AM +0200, Christophe JAILLET wrote:
> > > Use sysfs_emit_at() instead of snprintf() + custom logic.
> > > Using sysfs_emit_at() is much more simple.
> > >
> > > Also, sysfs_emit() is already used in this function, so using
> > > sysfs_emit_at() is more consistent.
> > >
> > > Also simplify the logic:
> > > - always add a space after an entry
> > > - change the last space into a '\n'
> > >
> > > Finally it is easy to see that, given the size of cabc_modes, PAGE_SIZE
> > > can not be reached.
> > > So better keep everything simple (and correct).
> > >
> > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > > ---
> > > .../omap2/omapfb/displays/panel-sony-acx565akm.c | 15 ++++++++-------
> > > 1 file changed, 8 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
> > > index 71d2e015960c..fc975615d5c9 100644
> > > --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
> > > +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
> > > @@ -466,19 +466,20 @@ static ssize_t show_cabc_available_modes(struct device *dev,
> > > char *buf)
> > > {
> > > struct panel_drv_data *ddata = dev_get_drvdata(dev);
> > > - int len;
> > > + int len = 0;
> > > int i;
> > > if (!ddata->has_cabc)
> > > return sysfs_emit(buf, "%s\n", cabc_modes[0]);
> > > - for (i = 0, len = 0;
> > > - len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
> > > - len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
> > > - i ? " " : "", cabc_modes[i],
> > > - i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
> > > + for (i = 0; i < ARRAY_SIZE(cabc_modes); i++)
> > > + len += sysfs_emit_at(buf, len, "%s ", cabc_modes[i]);
> > > +
> > > + /* Remove the trailing space */
> > > + if (len)
> > > + buf[len - 1] = '\n';
> >
> > I'm uncomfortable with this line. It assumes we don't overflow PAGE_SIZE where
> > the original code was careful about checking. Probably easiest to do what the
> > original code did and say:
> >
>
> Hi Dan,
>
> I don't follow you. AFAIK, it does not assume anything.
>
> Thanks to sysfs_emit_at(), len can only be in [0..PAGE_SIZE-1] because the
> trailing \0 is not counted.
>
Ah, you're right. Sorry for the noise.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] fbdev: omapfb: panel-sony-acx565akm: Simplify show_cabc_available_modes()
2024-08-08 9:46 [PATCH] fbdev: omapfb: panel-sony-acx565akm: Simplify show_cabc_available_modes() Christophe JAILLET
2024-08-08 10:25 ` Andi Shyti
2024-08-09 14:42 ` Dan Carpenter
@ 2024-08-28 18:08 ` Helge Deller
2 siblings, 0 replies; 7+ messages in thread
From: Helge Deller @ 2024-08-28 18:08 UTC (permalink / raw)
To: Christophe JAILLET
Cc: linux-kernel, kernel-janitors, linux-omap, linux-fbdev, dri-devel
On 8/8/24 11:46, Christophe JAILLET wrote:
> Use sysfs_emit_at() instead of snprintf() + custom logic.
> Using sysfs_emit_at() is much more simple.
>
> Also, sysfs_emit() is already used in this function, so using
> sysfs_emit_at() is more consistent.
>
> Also simplify the logic:
> - always add a space after an entry
> - change the last space into a '\n'
>
> Finally it is easy to see that, given the size of cabc_modes, PAGE_SIZE
> can not be reached.
> So better keep everything simple (and correct).
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
applied.
Thanks!
Helge
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-08-28 18:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08 9:46 [PATCH] fbdev: omapfb: panel-sony-acx565akm: Simplify show_cabc_available_modes() Christophe JAILLET
2024-08-08 10:25 ` Andi Shyti
2024-08-09 14:42 ` Dan Carpenter
2024-08-09 14:48 ` Dan Carpenter
2024-08-09 15:09 ` Christophe JAILLET
2024-08-09 15:13 ` Dan Carpenter
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