mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Siqi Chen <chensiqi@uniontech.com>
To: Lukas Timmermann <linux@timmermann.space>,
	Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>
Cc: Griffin Kroah-Hartman <griffin@kroah.com>,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	Siqi Chen <chensiqi@uniontech.com>,
	stable@vger.kernel.org
Subject: [PATCH] leds: as3668: Propagate chip ID read errors
Date: Tue, 17 Nov 2026 16:39:17 +0800	[thread overview]
Message-ID: <20261117083917.3304865-1-chensiqi@uniontech.com> (raw)

i2c_smbus_read_byte_data() returns a negative error code on failure.
Storing the result in a u8 truncates that error and causes probe to
report a bogus chip ID and return -ENODEV.

Store the result in an int and propagate read failures before checking
the chip ID.

An AI coding assistant was used to identify the issue and help develop
the fix.

The change was compile-tested with W=1. No hardware testing was
performed.

Fixes: c7dd343a3756 ("leds: as3668: Driver for the ams Osram 4-channel i2c LED driver")
Cc: stable@vger.kernel.org
Signed-off-by: Siqi Chen <chensiqi@uniontech.com>
---
 drivers/leds/leds-as3668.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/leds-as3668.c b/drivers/leds/leds-as3668.c
index 46427fe752a8..6e4b6ad59059 100644
--- a/drivers/leds/leds-as3668.c
+++ b/drivers/leds/leds-as3668.c
@@ -131,10 +131,13 @@ static int as3668_dt_init(struct as3668 *as3668)
 static int as3668_probe(struct i2c_client *client)
 {
 	struct as3668 *as3668;
-	int err;
-	u8 chip_id;
+	int chip_id, err;
 
 	chip_id = i2c_smbus_read_byte_data(client, AS3668_CHIP_ID1_REG);
+	if (chip_id < 0)
+		return dev_err_probe(&client->dev, chip_id,
+				     "failed to read chip ID\n");
+
 	if (chip_id != AS3668_CHIP_ID)
 		return dev_err_probe(&client->dev, -ENODEV,
 				     "expected chip ID 0x%02x, got 0x%02x\n",
-- 
2.20.1


                 reply	other threads:[~2026-11-17  8:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261117083917.3304865-1-chensiqi@uniontech.com \
    --to=chensiqi@uniontech.com \
    --cc=griffin@kroah.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux@timmermann.space \
    --cc=pavel@kernel.org \
    --cc=stable@vger.kernel.org \
    /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®