From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D04E931C567 for ; Sat, 4 Apr 2026 20:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775336340; cv=none; b=AobO8j+KgUkcEjhVz9xM0oGbssIWhg6+nL4ri28mGU75X82HNNGp7oPf0fGeELwDIopkXo+McUkva2xd7H6YiQP2r5n5RX1DN9rrN9PR45dNd6jYPHVTp6EI1jFkhrJz0TtAtiQeoARmzewfiXOCgHR+BPtFJpQQrMoGr7TnHqI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775336340; c=relaxed/simple; bh=PQurDO6OXhnVPnvpUtqOGS5FT+WIsaPPR8yY5aKiW/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u+9sSQa69GDx9UUd/6NNQRvSow2MpM6YfII0A2LsnF652sy0ygwfOod5StbcIgdl47b2yNFiE1AABVaYv4IQVeg+aKoSiHK1Z7Nd+/LljRsyVv/KNuXVvAi/uOMmlhRP3E3iTzA6XHPSquM3EPZtC1uxRvptX5XuOeBrYZhFPZE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fK6dxg0j; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fK6dxg0j" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-488ab2db91aso1856065e9.3 for ; Sat, 04 Apr 2026 13:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775336337; x=1775941137; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iPUiQBF9d8UvPDKEpZeV7b1Q9KHNeEe04jRYcpwMjow=; b=fK6dxg0jJqzSDawXAwx3Vjmd66lExzwrhUtZCmwQJJZtzdM+DnBF/qjrlTxiANh6fs q4gn15kyte/d4lPuCfDhKRl+65aPMyZdfuLvf+BJ29oXMKLNAGCsu+IlPINAFkQ7/g3h fbfE4v2N0pvaGXGLRzw1AHb1ffoNzX2Ky9YxeCLZy5umkGhqvI6Hq6Czbmr6+r3nQv+L Cy0pJHzoBTGwQ7TD7XVNN3SDR+pT0EaSapHXmhbRtA6KqLosSHx3KHQ4b0VEBiEeQbbK Lu8fygt53w7pAe/HvzganC6bpOPSoBJsXId5LxpU3eUBXhgyrNYcwG215E9PhED6Cu/R EbFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775336337; x=1775941137; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iPUiQBF9d8UvPDKEpZeV7b1Q9KHNeEe04jRYcpwMjow=; b=cEXBtx3ZZyCO8MF8dvmqv76bYCJjpR/KSBQs8IGzuJ2diZbROB2xt6Oz8qmjp4PqAT d4o6XFgwdITGEnV0XRUwuaaiY/cphkW2l76RQl59RsBvyQbmvdjlP5OldKqAupAwzV9A 0je6F8S7pQlnOb7h63OGAx82j9fMWxlq8/zFFTWlJJ+cKCHyQW4akDXQnaF/BnzrMZR+ uKcZDZdN2d0lN3+teXswYTnbHXFLRA33PfcGz4xqK4z+uDU6I5hFS8sOS4eCrxLdDZbz Bbf2XPf+TwvjZmtLaDakiMqEg5GFlfwLfN6EcfIsICYYpBKdQ5QSJ5Bluz/KGgqDoaEn YNZQ== X-Forwarded-Encrypted: i=1; AJvYcCWAgY3qdzI8Ong+jKbX9QAuLkjCpB8jUwdGTk2OOKSZQ4Z1xy83ZZwLL6+pzLWAhGc743zhPfgPkax93vg=@vger.kernel.org X-Gm-Message-State: AOJu0YwC995KP5m0K8TYy6UGn+D7wgLCt5nU+Rybg5EHEwIqULCk9hF5 Abg5Ag6w6QPQEpUIjgMJL56ezvrDbyFPRPlm7R9gW3N4anuUdUP8h3IP X-Gm-Gg: AeBDietNfORH7Tjg6DChvDaBbS+IIRJbkn2X4k4kr+NpVJZhaCnUu3XWdjF1lNSRnXG ndp6ShnhjEEqNMliwS4p3QSX3hhtfN8hvsmU84DGiQGtLTs7OmHSQr2xtEGDdz9cByx5SRSIegQ A0X6eVIBueypoD0vM5ucaEP7jFQxjLUXXvZ8ejVixaqhnHS4SnArPDyXPSJH1CsZyHVhBLAq/ME fxUNZxZY/ENj6rEAV1BKqa/m7OL7wpWQVGxcjOTZZ/JDm/5L94QeVQrxPCNctPfMoGgMXnpteu5 /2iZSjMCpsKMw14oAaflapQbFOOr3/hxbc6W3OvMxh/HuBC4pwc0zyNTvdKIqXa3X+4r/nmUI2J r4HVe+1wlapUb9NCzns6JAN4HvjfjWxCw++kU8bEzQ4P5NSKPNCrsOOwmPZeyDTozy56AD9nNRq Mm+DegLXNmQJ27qcnrcGbiFGIxytq8+ZaRDmNCB8cM3jE5UXAA4M/U X-Received: by 2002:a05:600c:64c7:b0:488:a8f0:35bd with SMTP id 5b1f17b1804b1-488a8f037c4mr30177285e9.8.1775336337032; Sat, 04 Apr 2026 13:58:57 -0700 (PDT) Received: from aldo-conte-t14.tailf68ad9.ts.net ([94.164.143.38]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488a36f22b1sm84749535e9.10.2026.04.04.13.58.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2026 13:58:56 -0700 (PDT) From: Aldo Conte To: jic23@kernel.org Cc: ktsai@capellamicro.com, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, daniel.baluta@intel.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, me@brighamcampbell.com, linux-kernel-mentees@lists.linux.dev Subject: [PATCH v2 1/2] iio: light: cm3323: fix reg_conf not being initialized correctly Date: Sat, 4 Apr 2026 22:58:51 +0200 Message-ID: <20260404205853.18559-2-aldocontelk@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260404205853.18559-1-aldocontelk@gmail.com> References: <20260404205853.18559-1-aldocontelk@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The code stores the return value of i2c_smbus_write_word_data() in data->reg_conf; however, this value represents the result of the write operation and not the value actually written to the configuration register. This meant that the contents of data->reg_conf did not truly reflect the contents of the hardware register. Instead, save the value of the register before the write and use this value in the I2C write. The bug was found by code inspection: i2c_smbus_write_word_data() returns 0 on success, not the value written to the register. Tested using i2c-stub on a Raspberry Pi 3B running a custom 6.19.10 kernel. Before loading the driver, the configuration register 0x00 CM3323_CMD_CONF was populated with 0x0030 using `i2cset -y 11 0x10 0x00 0x0030 w`, encoding an integration time of 320ms in bits[6:4]. Due to incorrect initialization of data->reg_conf in cm3323_init(), the print of integration_time returns 0.040000 instead of the expected 0.320000. This happens because the read of the integration_time depends on cm3323_get_it_bits() that is based on the value of data->reg_conf, which is erroneously set to 0. With this fix applied, data->reg_conf correctly saves 0x0030 after init and the successive integration_time reports 0.320000 as expected. Fixes: 8b0544263761 ("iio: light: Add support for Capella CM3323 color sensor") Cc: stable@vger.kernel.org Signed-off-by: Aldo Conte --- Changes in v2: - fix typos in commit message drivers/iio/light/cm3323.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/iio/light/cm3323.c b/drivers/iio/light/cm3323.c index 79ad6e2209ca..0fe61b8a7029 100644 --- a/drivers/iio/light/cm3323.c +++ b/drivers/iio/light/cm3323.c @@ -89,15 +89,14 @@ static int cm3323_init(struct iio_dev *indio_dev) /* enable sensor and set auto force mode */ ret &= ~(CM3323_CONF_SD_BIT | CM3323_CONF_AF_BIT); + data->reg_conf = ret; - ret = i2c_smbus_write_word_data(data->client, CM3323_CMD_CONF, ret); + ret = i2c_smbus_write_word_data(data->client, CM3323_CMD_CONF, data->reg_conf); if (ret < 0) { dev_err(&data->client->dev, "Error writing reg_conf\n"); return ret; } - data->reg_conf = ret; - return 0; } -- 2.53.0