mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: shao.mingyin@zte.com.cn
Cc: mfd@lists.linux.dev, tharvey@gateworks.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] mfd: gateworks-gsc: Propagate I2C read errors
Date: Wed, 18 Nov 2026 20:37:32 +0000	[thread overview]
Message-ID: <179442103029.44545.1262285836401934201@kernel.org> (raw)
In-Reply-To: <202611091914028089L4I88l9WGcWziY8r3qZb@zte.com.cn>

On Mon, 09 Nov 2026, shao.mingyin@zte.com.cn wrote:

> From: Shao Mingyin <shao.mingyin@zte.com.cn>
>
> gsc_read() retries the I2C transfer but then stores "ret & 0xff" in *val
> and returns 0 even when the transfer failed.  regmap_read() therefore
> never reports an error, so the FW_VER check in gsc_probe() and the two
> GSC_FW_CRC checks that this patch adds are dead code, and on a failed
> read the firmware revision is built from the low byte of the negative
> errno.
>
> Return the error from gsc_read() before touching *val, so regmap_read()
> and its callers see the failure; the FW_VER check and the two CRC checks
> then work as intended.
>
> Fixes: d85234994b2f ("mfd: Add Gateworks System Controller core driver")
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
> ---
> This supersedes 5/5 of the RESEND series; 1/5-4/5 are unchanged.
>
> v3:
>   - reword the commit message: the two GSC_FW_CRC checks are added by this
>     patch, so say that instead of referring to "the previous version"; the
>     second paragraph no longer calls them pre-existing.  No code change
> v2: https://lore.kernel.org/all/20261108151125513PyebyF3QC3r_DTxS9ZMf6@zte.com.cn/
> v1: https://lore.kernel.org/all/20261107162125044ldKkwYPQxZOTWg6IDe_LX@zte.com.cn/
>
> diff --git a/drivers/mfd/gateworks-gsc.c b/drivers/mfd/gateworks-gsc.c
> --- a/drivers/mfd/gateworks-gsc.c
> +++ b/drivers/mfd/gateworks-gsc.c
> @@ -62,7 +62,10 @@ int gsc_read(void *context, unsigned int reg, unsigned int *val)
>  		if (ret != -EAGAIN && ret != -EIO)
>  			break;
>  	}
> -	*val = ret & 0xff;
> +	if (ret < 0)
> +		return ret;
> +
> +	*val = ret;
>
>  	return 0;
>  }
> @@ -219,9 +222,11 @@ static int gsc_probe(struct i2c_client *client)
>  		return -EIO;
>  	gsc->fwver = reg;
>
> -	regmap_read(gsc->regmap, GSC_FW_CRC, &reg);
> +	if (regmap_read(gsc->regmap, GSC_FW_CRC, &reg))
> +		return -EIO;

Should we propagate the return value of regmap_read()?

Also, really not a fan of functions in if()s.

>  	gsc->fwcrc = reg;
> -	regmap_read(gsc->regmap, GSC_FW_CRC + 1, &reg);
> +	if (regmap_read(gsc->regmap, GSC_FW_CRC + 1, &reg))
> +		return -EIO;
>  	gsc->fwcrc |= reg << 8;
>
>  	gsc->i2c_hwmon = devm_i2c_new_dummy_device(dev, client->adapter,
> -- 
> 2.47.0

-- 
Lee Jones

      reply	other threads:[~2026-11-18 20:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 11:14 shao.mingyin
2026-11-18 20:37 ` Lee Jones [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=179442103029.44545.1262285836401934201@kernel.org \
    --to=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mfd@lists.linux.dev \
    --cc=shao.mingyin@zte.com.cn \
    --cc=tharvey@gateworks.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

all inboxes | Powered by JetHome®