From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 055033630B8 for ; Tue, 7 Apr 2026 15:17:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775575030; cv=none; b=RsHLsCPpCmwg6qT5IN57sgJO7elaMg1U2TrDGfgFVQntz8W6r6HZ2yCBmWtxn7nUNjWS4AXqsFlz3i+Khj0r790Y4+D1gnJdZdzFUYZXsunwuzrHZjziD6h02cLBTBx7Rz9Hc/G3E8Pnby+r4K+k5Y8dQ7O+Ruq3ZCH5Bmio2k8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775575030; c=relaxed/simple; bh=bMBU/Sp/Hd+8dWJzIBSChhEWAq6h8QnFVVi6t0Td8CM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LJmoUP21GEFPDb+fUfPt/kB+s2LES06e09DF2HiWSEhZz/35kYXAmsZW8FOr0yaUYebruN4Ic8fwv7N9odRPNIWW68Fy3Ys41yTyrZwls48oMbxIdg9Jfgoqlomwlo6fGRjamrvYlcrckPPkonOY71oQN4gLJocAbz220SyyYqA= 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=lSnqMTS9; arc=none smtp.client-ip=209.85.221.43 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="lSnqMTS9" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-43b8e8e7432so4219334f8f.1 for ; Tue, 07 Apr 2026 08:17:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775575027; x=1776179827; 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=I7ul7R4AdJ4kZnhxBsfC1ozDk40Au8wWcQ7o5oSGrE0=; b=lSnqMTS9+wbM/oBZcgbxOGZKhLCkCDXgnvavJHOE9jyx/nW+DTT+BCCST0DniaCA5Q 6zerFEx/9u2aCoAIX0ZZDQZev8zma9nXtPpJUuyMIz1Bd11wpUEqB8uTMKQsVX9UFiCJ XjD7tKnXTRivw8RuMaqrTG+vshmSfz+y+y/brYyC9RqnhFkmNrCpbp2Lo6LyyR0VoBJT sciA2G1FZrxGBso3A1VKI0X14bMmojSl6BmarLJVo8pPUXxDy0dlF5GNtm7RPIltSyE9 grminKiiqxe6iCSnUeHsHmNhPOVAulunqHprRnKa50fiIgTdVsUn7y1IAxpv3UtGMrit +itw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775575027; x=1776179827; 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=I7ul7R4AdJ4kZnhxBsfC1ozDk40Au8wWcQ7o5oSGrE0=; b=GRlkYUV8iOECziMzBvs3cfH5t29t7+F9js6KYkmhq3VLT+39UsnsGC0H/evHlFdUKw uLiIuJFS9oXeUpRTOOSF128sLPUYeEC/N4QNpg9jKr8DWstV9JBWQKMFsKmwgfvwjRSg 40A0GUL3j1OIIahSTHX6GH55rLS+ICKAKSYlu5xc/TbcKxgcStWk+5GMAinnRgJ/SvTd jmib7vem8U5r1pjZJk5DooW1bQEgC/CMoX4uC1zxqjp363oTtlR5M0JSwtIOGVo5PrQD gP/NGJ/zD3cw9pDyyzF0p6MVEYI8FMqE4SV1wsYE/ZpyqsT6lhYYALjmox8/ydwZ9uk8 I7SA== X-Forwarded-Encrypted: i=1; AJvYcCXB7jVcQrYNzLOLP+eIjQX/FwT6qsFXYBL0cVfRIkVLi+8pkGO6Lvi1HpM8VE6qNcib8elpCwFQ2oadqAY=@vger.kernel.org X-Gm-Message-State: AOJu0YwprYC6jvsq8SXKDwVSS59PBWxfGV/eNAVJ8q2gRu6b39a1FxUc 42dqN4CIwOlLahoMTfBmuqVtzMQkX2zkmIVh7/btB0Tx6T5VdWkCgkbZ X-Gm-Gg: AeBDietpKESTSUme18DBSPkuIxpRF1ldlR1R8at5gg2ILcfYUvTzoLwOQXc1svBnhM2 GZ4iU/v9em0KhmNZv5IyEYONtgLGrYb1884h6f8/nSo4/hHvlP4ffPBiq/AsinDj9kSlA7w7hbe xVL0PSPa9y9V4c+FDvHhZjT4sV5QYPwbYrGSjZd7vRaB16Ft6W1cjLVoXPPCq9+MZ4xnXtCHlTd FWvM61BH/DmgYBvlMdo+cOZgF2B7Rx4tN3WnoAFNN0fMdqg8TsN6PKQYTrJMCn7Ci5y26D5yBhh q0l5KEAAy+5797QvfUUFCJP0L/zNPGMQCsdNHWuUYGb7annwrWtkmEZnHyw7+1yM9Mhh7iuFUkv yYu8LehZVassXB8qlS+qszq60QjGHA1kzEnNBi8Np1eNTc6CwSGD55LvRRgA23OjTjtjdjkz/GJ f94kPbuGjHzZoMwldod9Dd3xqGezykIpgxd+6ysLhVe/2fOQHW260= X-Received: by 2002:a05:6000:184d:b0:43d:61:652a with SMTP id ffacd0b85a97d-43d292e8ab6mr25974359f8f.40.1775575027008; Tue, 07 Apr 2026 08:17:07 -0700 (PDT) Received: from aldo-conte-t14.tailf68ad9.ts.net ([37.163.52.91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d1e2a6f13sm51924922f8f.3.2026.04.07.08.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 08:17:06 -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 v4 1/2] iio: light: cm3323: fix reg_conf not being initialized correctly Date: Tue, 7 Apr 2026 17:17:01 +0200 Message-ID: <20260407151702.15208-2-aldocontelk@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260407151702.15208-1-aldocontelk@gmail.com> References: <20260407151702.15208-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 --- 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