diff mbox series

[v2] drm,fbdev: td043mtea1: Convert sprintf() family to sysfs_emit() family

Message ID 20240319035555.1577734-1-lizhijian@fujitsu.com (mailing list archive)
State New, archived
Headers show
Series [v2] drm,fbdev: td043mtea1: Convert sprintf() family to sysfs_emit() family | expand

Commit Message

Zhijian Li (Fujitsu) March 19, 2024, 3:55 a.m. UTC
Per filesystems/sysfs.rst, show() should only use sysfs_emit()
or sysfs_emit_at() when formatting the value to be returned to user space.

coccinelle complains that there are still a couple of functions that use
snprintf(). Convert them to sysfs_emit().

sprintf() and scnprintf() will be converted as well if they have.

Generally, this patch is generated by
make coccicheck M=<path/to/file> MODE=patch \
COCCI=scripts/coccinelle/api/device_attr_show.cocci

No functional change intended

CC: Neil Armstrong <neil.armstrong@linaro.org>
CC: Jessica Zhang <quic_jesszhan@quicinc.com>
CC: Sam Ravnborg <sam@ravnborg.org>
CC: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
CC: Maxime Ripard <mripard@kernel.org>
CC: Thomas Zimmermann <tzimmermann@suse.de>
CC: David Airlie <airlied@gmail.com>
CC: Daniel Vetter <daniel@ffwll.ch>
CC: Helge Deller <deller@gmx.de>
CC: linux-omap@vger.kernel.org
CC: linux-fbdev@vger.kernel.org
CC: dri-devel@lists.freedesktop.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
V2:
   Fix missing '+' before '=' in drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c

This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
Split them per subsystem so that the maintainer can review it easily
[1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/gpu/drm/panel/panel-tpo-td043mtea1.c        | 13 ++++---------
 .../omap2/omapfb/displays/panel-tpo-td043mtea1.c    | 12 ++++--------
 2 files changed, 8 insertions(+), 17 deletions(-)

Comments

Neil Armstrong March 19, 2024, 8:07 a.m. UTC | #1
Hi,

On 19/03/2024 04:55, Li Zhijian wrote:
> Per filesystems/sysfs.rst, show() should only use sysfs_emit()
> or sysfs_emit_at() when formatting the value to be returned to user space.
> 
> coccinelle complains that there are still a couple of functions that use
> snprintf(). Convert them to sysfs_emit().
> 
> sprintf() and scnprintf() will be converted as well if they have.
> 
> Generally, this patch is generated by
> make coccicheck M=<path/to/file> MODE=patch \
> COCCI=scripts/coccinelle/api/device_attr_show.cocci
> 
> No functional change intended

Please split patches in 2, while the driver targets the same hw, they
are not under the same subsystems.

Neil

> 
> CC: Neil Armstrong <neil.armstrong@linaro.org>
> CC: Jessica Zhang <quic_jesszhan@quicinc.com>
> CC: Sam Ravnborg <sam@ravnborg.org>
> CC: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> CC: Maxime Ripard <mripard@kernel.org>
> CC: Thomas Zimmermann <tzimmermann@suse.de>
> CC: David Airlie <airlied@gmail.com>
> CC: Daniel Vetter <daniel@ffwll.ch>
> CC: Helge Deller <deller@gmx.de>
> CC: linux-omap@vger.kernel.org
> CC: linux-fbdev@vger.kernel.org
> CC: dri-devel@lists.freedesktop.org
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
> V2:
>     Fix missing '+' before '=' in drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c
> 
> This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
> Split them per subsystem so that the maintainer can review it easily
> [1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@fujitsu.com/
> ---
>   drivers/gpu/drm/panel/panel-tpo-td043mtea1.c        | 13 ++++---------
>   .../omap2/omapfb/displays/panel-tpo-td043mtea1.c    | 12 ++++--------
>   2 files changed, 8 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
> index cf4609bb9b1d..0983fe47eb5a 100644
> --- a/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
> +++ b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
> @@ -242,16 +242,11 @@ static ssize_t gamma_show(struct device *dev, struct device_attribute *attr,
>   	struct td043mtea1_panel *lcd = dev_get_drvdata(dev);
>   	ssize_t len = 0;
>   	unsigned int i;
> -	int ret;
>   
> -	for (i = 0; i < ARRAY_SIZE(lcd->gamma); i++) {
> -		ret = snprintf(buf + len, PAGE_SIZE - len, "%u ",
> -			       lcd->gamma[i]);
> -		if (ret < 0)
> -			return ret;
> -		len += ret;
> -	}
> -	buf[len - 1] = '\n';
> +	for (i = 0; i < ARRAY_SIZE(lcd->gamma); i++)
> +		len += sysfs_emit_at(buf, len, "%u ", lcd->gamma[i]);
> +	if (len)
> +		buf[len - 1] = '\n';
>   
>   	return len;
>   }
> diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c
> index 477789cff8e0..3624452e1dd0 100644
> --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c
> +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c
> @@ -228,14 +228,10 @@ static ssize_t tpo_td043_gamma_show(struct device *dev,
>   	int ret;
>   	int i;
>   
> -	for (i = 0; i < ARRAY_SIZE(ddata->gamma); i++) {
> -		ret = snprintf(buf + len, PAGE_SIZE - len, "%u ",
> -				ddata->gamma[i]);
> -		if (ret < 0)
> -			return ret;
> -		len += ret;
> -	}
> -	buf[len - 1] = '\n';
> +	for (i = 0; i < ARRAY_SIZE(ddata->gamma); i++)
> +		len += sysfs_emit_at(buf, len, "%u ", ddata->gamma[i]);
> +	if (len)
> +		buf[len - 1] = '\n';
>   
>   	return len;
>   }
Zhijian Li (Fujitsu) March 19, 2024, 9:05 a.m. UTC | #2
On 19/03/2024 16:07, Neil Armstrong wrote:
> Hi,
> 
> On 19/03/2024 04:55, Li Zhijian wrote:
>> Per filesystems/sysfs.rst, show() should only use sysfs_emit()
>> or sysfs_emit_at() when formatting the value to be returned to user space.
>>
>> coccinelle complains that there are still a couple of functions that use
>> snprintf(). Convert them to sysfs_emit().
>>
>> sprintf() and scnprintf() will be converted as well if they have.
>>
>> Generally, this patch is generated by
>> make coccicheck M=<path/to/file> MODE=patch \
>> COCCI=scripts/coccinelle/api/device_attr_show.cocci
>>
>> No functional change intended
> 
> Please split patches in 2, while the driver targets the same hw, they
> are not under the same subsystems.

Got it, i will do that soon.

Thanks
Zhijian

> 
> Neil
> 
>>
>> CC: Neil Armstrong <neil.armstrong@linaro.org>
>> CC: Jessica Zhang <quic_jesszhan@quicinc.com>
>> CC: Sam Ravnborg <sam@ravnborg.org>
>> CC: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>> CC: Maxime Ripard <mripard@kernel.org>
>> CC: Thomas Zimmermann <tzimmermann@suse.de>
>> CC: David Airlie <airlied@gmail.com>
>> CC: Daniel Vetter <daniel@ffwll.ch>
>> CC: Helge Deller <deller@gmx.de>
>> CC: linux-omap@vger.kernel.org
>> CC: linux-fbdev@vger.kernel.org
>> CC: dri-devel@lists.freedesktop.org
>> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
>> ---
>> V2:
>>     Fix missing '+' before '=' in drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c
>>
>> This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
>> Split them per subsystem so that the maintainer can review it easily
>> [1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@fujitsu.com/
>> ---
>>   drivers/gpu/drm/panel/panel-tpo-td043mtea1.c        | 13 ++++---------
>>   .../omap2/omapfb/displays/panel-tpo-td043mtea1.c    | 12 ++++--------
>>   2 files changed, 8 insertions(+), 17 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
>> index cf4609bb9b1d..0983fe47eb5a 100644
>> --- a/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
>> +++ b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
>> @@ -242,16 +242,11 @@ static ssize_t gamma_show(struct device *dev, struct device_attribute *attr,
>>       struct td043mtea1_panel *lcd = dev_get_drvdata(dev);
>>       ssize_t len = 0;
>>       unsigned int i;
>> -    int ret;
>> -    for (i = 0; i < ARRAY_SIZE(lcd->gamma); i++) {
>> -        ret = snprintf(buf + len, PAGE_SIZE - len, "%u ",
>> -                   lcd->gamma[i]);
>> -        if (ret < 0)
>> -            return ret;
>> -        len += ret;
>> -    }
>> -    buf[len - 1] = '\n';
>> +    for (i = 0; i < ARRAY_SIZE(lcd->gamma); i++)
>> +        len += sysfs_emit_at(buf, len, "%u ", lcd->gamma[i]);
>> +    if (len)
>> +        buf[len - 1] = '\n';
>>       return len;
>>   }
>> diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c
>> index 477789cff8e0..3624452e1dd0 100644
>> --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c
>> +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c
>> @@ -228,14 +228,10 @@ static ssize_t tpo_td043_gamma_show(struct device *dev,
>>       int ret;
>>       int i;
>> -    for (i = 0; i < ARRAY_SIZE(ddata->gamma); i++) {
>> -        ret = snprintf(buf + len, PAGE_SIZE - len, "%u ",
>> -                ddata->gamma[i]);
>> -        if (ret < 0)
>> -            return ret;
>> -        len += ret;
>> -    }
>> -    buf[len - 1] = '\n';
>> +    for (i = 0; i < ARRAY_SIZE(ddata->gamma); i++)
>> +        len += sysfs_emit_at(buf, len, "%u ", ddata->gamma[i]);
>> +    if (len)
>> +        buf[len - 1] = '\n';
>>       return len;
>>   }
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
index cf4609bb9b1d..0983fe47eb5a 100644
--- a/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
+++ b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
@@ -242,16 +242,11 @@  static ssize_t gamma_show(struct device *dev, struct device_attribute *attr,
 	struct td043mtea1_panel *lcd = dev_get_drvdata(dev);
 	ssize_t len = 0;
 	unsigned int i;
-	int ret;
 
-	for (i = 0; i < ARRAY_SIZE(lcd->gamma); i++) {
-		ret = snprintf(buf + len, PAGE_SIZE - len, "%u ",
-			       lcd->gamma[i]);
-		if (ret < 0)
-			return ret;
-		len += ret;
-	}
-	buf[len - 1] = '\n';
+	for (i = 0; i < ARRAY_SIZE(lcd->gamma); i++)
+		len += sysfs_emit_at(buf, len, "%u ", lcd->gamma[i]);
+	if (len)
+		buf[len - 1] = '\n';
 
 	return len;
 }
diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c
index 477789cff8e0..3624452e1dd0 100644
--- a/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c
+++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c
@@ -228,14 +228,10 @@  static ssize_t tpo_td043_gamma_show(struct device *dev,
 	int ret;
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(ddata->gamma); i++) {
-		ret = snprintf(buf + len, PAGE_SIZE - len, "%u ",
-				ddata->gamma[i]);
-		if (ret < 0)
-			return ret;
-		len += ret;
-	}
-	buf[len - 1] = '\n';
+	for (i = 0; i < ARRAY_SIZE(ddata->gamma); i++)
+		len += sysfs_emit_at(buf, len, "%u ", ddata->gamma[i]);
+	if (len)
+		buf[len - 1] = '\n';
 
 	return len;
 }