Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: haibo.chen@oss.nxp.com
Cc: Adrian Hunter <adrian.hunter@intel.com>,
	Ulf Hansson <ulfh@kernel.org>, Yinbo Zhu <yinbo.zhu@nxp.com>,
	linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	imx@lists.linux.dev, Haibo Chen <haibo.chen@nxp.com>
Subject: Re: [PATCH] mmc: sdhci: make tuning_err a signed int
Date: Mon, 27 Jul 2026 09:52:28 -0500	[thread overview]
Message-ID: <amdwrKu5KP82r-Yf@SMW015318> (raw)
In-Reply-To: <20260727-sdhci-fix-v1-1-1a655a5d895d@nxp.com>

On Mon, Jul 27, 2026 at 06:38:49PM +0800, haibo.chen@oss.nxp.com wrote:
> From: Haibo Chen <haibo.chen@nxp.com>
>
> Coverity report INTEGER_OVERFLOW for host->tuning_err.
> The tuning_err field in struct sdhci_host is used to store an error
> code for re-tuning, but it was declared as unsigned int. Several call
> sites store negative error codes into it and later compare against
> negative values:
>
>   - sdhci.c, sdhci-of-dwcmshc.c and sdhci-pci-gli.c assign it the
>     return value of __sdhci_execute_tuning()/__sdhci_execute_tuning_9750(),
>     both of which return a signed int (possibly a negative errno);
>   - sdhci-of-esdhc.c assigns host->tuning_err = -EAGAIN and later does
>     "ret = host->tuning_err; if (ret == -EAGAIN ...)";
>   - sdhci-of-dwcmshc.c prints it with the %d (signed) conversion.
>
> Storing a negative errno in an unsigned int and reading it back as a
> signed int only happens to work because of two's-complement, same-width
> integer conversions. It is misleading and triggers sign-conversion
> warnings. All users treat the value either as a signed error code or as
> a boolean (zero / non-zero), so changing the type to a signed int is
> safe and makes the intent explicit.
>
> Fixes: 7d8bb1f46e13 ("mmc: sdhci: add tuning error codes")
> Assisted-by: Cline:claude-sonnet [read_file, search_files, git]
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/mmc/host/sdhci.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
> index b6a571d866fa53ce2aad0105cea2909abe6bce01..f0fd81409a86c6fd9120e69766fa2407c14e9048 100644
> --- a/drivers/mmc/host/sdhci.h
> +++ b/drivers/mmc/host/sdhci.h
> @@ -659,7 +659,7 @@ struct sdhci_host {
>
>  	unsigned int		tuning_count;	/* Timer count for re-tuning */
>  	unsigned int		tuning_mode;	/* Re-tuning mode supported by host */
> -	unsigned int		tuning_err;	/* Error code for re-tuning */
> +	int			tuning_err;	/* Error code for re-tuning */
>  #define SDHCI_TUNING_MODE_1	0
>  #define SDHCI_TUNING_MODE_2	1
>  #define SDHCI_TUNING_MODE_3	2
>
> ---
> base-commit: c5e32e86ca02b003f86e095d379b38148999293d
> change-id: 20260727-sdhci-fix-13481630ae02
>
> Best regards,
> --
> Haibo Chen <haibo.chen@nxp.com>
>
>

      reply	other threads:[~2026-07-27 14:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 10:38 [PATCH] mmc: sdhci: make tuning_err a signed int haibo.chen
2026-07-27 14:52 ` Frank Li [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=amdwrKu5KP82r-Yf@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=adrian.hunter@intel.com \
    --cc=haibo.chen@nxp.com \
    --cc=haibo.chen@oss.nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulfh@kernel.org \
    --cc=yinbo.zhu@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox