Re: [PATCH] mmc: sdhci: make tuning_err a signed int
Ulf Hansson <[email protected]> Tue, 4 Aug 2026 15:42:49 +0200
| Newsgroups | org.kernel.vger.linux-mmc,dev.linux.lists.imx,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAPx+jO81304unQwypjFLvYj108u5r1FJy4j3NeiZ-JR=VXde8A@mail.gmail.com> |
On Mon, Jul 27, 2026 at 12:35=E2=80=AFPM <[email protected]> wrote: > > From: Haibo Chen <[email protected]> > > 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 =3D -EAGAIN and later does > "ret =3D host->tuning_err; if (ret =3D=3D -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 <[email protected]> Applied for fixes and by adding a stable tag, thanks! Kind regards Uffe > --- > 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..f0fd81409a86c6fd9120e6976= 6fa2407c14e9048 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-tun= ing */ > unsigned int tuning_mode; /* Re-tuning mode support= ed by host */ > - unsigned int tuning_err; /* Error code for re-tuni= ng */ > + int tuning_err; /* Error code for re-tuni= ng */ > #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 <[email protected]> >