[PATCH 8/8] ASoC: omap: Replace sprintf() with sysfs_emit()

Péter Ujfalusi peter.ujfalusi at gmail.com
Mon Aug 1 20:54:28 CEST 2022



On 01/08/2022 20:01, Takashi Iwai wrote:
> For sysfs outputs, it's safer to use a new helper, sysfs_emit(),
> instead of the raw sprintf() & co.  This patch replaces the open code
> with new helpers, sysfs_emit() and sysfs_emit_at(), with the proper
> string offset.

Acked-by: Peter Ujfalusi <peter.ujfalusi at gmail.com>

> 
> Signed-off-by: Takashi Iwai <tiwai at suse.de>
> ---
>  sound/soc/ti/omap-mcbsp-st.c | 6 +++---
>  sound/soc/ti/omap-mcbsp.c    | 8 ++++----
>  2 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/sound/soc/ti/omap-mcbsp-st.c b/sound/soc/ti/omap-mcbsp-st.c
> index 7e8179cae92e..8163f453bf36 100644
> --- a/sound/soc/ti/omap-mcbsp-st.c
> +++ b/sound/soc/ti/omap-mcbsp-st.c
> @@ -244,10 +244,10 @@ static ssize_t st_taps_show(struct device *dev,
>  
>  	spin_lock_irq(&mcbsp->lock);
>  	for (i = 0; i < st_data->nr_taps; i++)
> -		status += sprintf(&buf[status], (i ? ", %d" : "%d"),
> -				  st_data->taps[i]);
> +		status += sysfs_emit_at(buf, status, (i ? ", %d" : "%d"),
> +					st_data->taps[i]);
>  	if (i)
> -		status += sprintf(&buf[status], "\n");
> +		status += sysfs_emit_at(buf, status, "\n");
>  	spin_unlock_irq(&mcbsp->lock);
>  
>  	return status;
> diff --git a/sound/soc/ti/omap-mcbsp.c b/sound/soc/ti/omap-mcbsp.c
> index c4ac1f30b9fe..0b377bb7737f 100644
> --- a/sound/soc/ti/omap-mcbsp.c
> +++ b/sound/soc/ti/omap-mcbsp.c
> @@ -517,7 +517,7 @@ static ssize_t prop##_show(struct device *dev,				\
>  {									\
>  	struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);		\
>  									\
> -	return sprintf(buf, "%u\n", mcbsp->prop);			\
> +	return sysfs_emit(buf, "%u\n", mcbsp->prop);			\
>  }									\
>  									\
>  static ssize_t prop##_store(struct device *dev,				\
> @@ -560,11 +560,11 @@ static ssize_t dma_op_mode_show(struct device *dev,
>  
>  	for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++) {
>  		if (dma_op_mode == i)
> -			len += sprintf(buf + len, "[%s] ", *s);
> +			len += sysfs_emit_at(buf, len, "[%s] ", *s);
>  		else
> -			len += sprintf(buf + len, "%s ", *s);
> +			len += sysfs_emit_at(buf, len, "%s ", *s);
>  	}
> -	len += sprintf(buf + len, "\n");
> +	len += sysfs_emit_at(buf, len, "\n");
>  
>  	return len;
>  }

-- 
Péter


More information about the Alsa-devel mailing list