[PATCH] pinctrl: mediatek: use scnprintf() instead of snprintf()
Julien Stephan
jstephan at baylibre.com
Thu May 7 10:34:22 CEST 2026
Le jeu. 7 mai 2026 à 01:05, David Lechner <dlechner at baylibre.com> a écrit :
>
> Replace snprintf() with scnprintf() in the MediaTek pinctrl driver.
>
> snprintf() returns the number of characters that _would_ have been
> written if the buffer were large enough, while scnprintf() returns the
> number of characters actually written to the buffer. Since we use the
> return value to advance the buffer pointer, we need to use scnprintf()
> to have the correct pointer arithmetic.
>
> Fixes: 76da7482cf39 ("pinctrl: mediatek: print bias info along with pinmux")
> Signed-off-by: David Lechner <dlechner at baylibre.com>
> ---
> drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> index cfffbaeef84..01f67f09407 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> @@ -251,7 +251,7 @@ static int mtk_pinconf_get(struct udevice *dev, u32 pin, char *buf, size_t size)
> if (mtk_get_pin_io_type(dev, pin, &io_type))
> return 0;
>
> - pos = snprintf(buf, size, " (%s)", io_type.name);
> + pos = scnprintf(buf, size, " (%s)", io_type.name);
> if (pos >= size)
> return pos;
>
> @@ -306,7 +306,7 @@ static int mtk_get_pin_muxing(struct udevice *dev, unsigned int selector,
> if (err)
> return err;
>
> - pos = snprintf(buf, size, "Aux Func.%d", val);
> + pos = scnprintf(buf, size, "Aux Func.%d", val);
> if (pos >= size)
> return 0;
>
> @@ -721,7 +721,7 @@ int mtk_pinconf_get_pu_pd(struct udevice *dev, u32 pin, char *buf, size_t size)
> if (err)
> return err;
>
> - return snprintf(buf, size, " PU:%d PD:%d", pu, pd);
> + return scnprintf(buf, size, " PU:%d PD:%d", pu, pd);
> }
>
> int mtk_pinconf_get_pupd_r1_r0(struct udevice *dev, u32 pin, char *buf, size_t size)
> @@ -740,7 +740,7 @@ int mtk_pinconf_get_pupd_r1_r0(struct udevice *dev, u32 pin, char *buf, size_t s
> if (err)
> return err;
>
> - return snprintf(buf, size, " PUPD:%d R1:%d R0:%d", pupd, r1, r0);
> + return scnprintf(buf, size, " PUPD:%d R1:%d R0:%d", pupd, r1, r0);
> }
>
> int mtk_pinconf_get_pu_pd_rsel(struct udevice *dev, u32 pin, char *buf, size_t size)
> @@ -755,7 +755,7 @@ int mtk_pinconf_get_pu_pd_rsel(struct udevice *dev, u32 pin, char *buf, size_t s
> if (err)
> return err;
>
> - return pos + snprintf(buf + pos, size - pos, " RSEL:%d", rsel);
> + return pos + scnprintf(buf + pos, size - pos, " RSEL:%d", rsel);
> }
> #endif
>
>
> ---
> base-commit: e08877916e24cf97d3afc67aee65ed2204790f48
> change-id: 20260506-mtk-pinctrl-fix-scnprintf-b5bfd1a31ed2
>
> Best regards,
> --
> David Lechner <dlechner at baylibre.com>
>
Hi David,
LGTM
Reviewed-by: Julien Stephan <jstephan at baylibre.com>
More information about the U-Boot
mailing list