From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 D79AD1EA84 for ; Thu, 7 May 2026 16:28:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778171320; cv=none; b=HnP3ebGxMlLFl45Yw45pJogSCMTcahRTwqTq1mXlMMjlT+ZRNbL5W+TOZgMA0bIz3GVKkBsdYpPJQTDzoVQuq05IZcTRzhCpenlm5bRGunMfZUAesyZY9nPFf9U4IW6tzw6ZwF2/vUBCpFSvsYbzJgpLubFLq8wBTPNd5THIcvs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778171320; c=relaxed/simple; bh=pwZ0Ke2yrpG5Ss5tVS/ttzElgT49ozq3iEhHeGIqCNU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EMgQFTkPg/w46t3E1BK3MpM35yXHptlbryfGl0x37PD7eWKU/LaWeDI9b7JvN0TbWJWkDNg9IYkrdO2weHfta5jTgNrL/Xwx3bDLE20OEPT7HcYTdv8JwHveBW0gX59PDzVTXjhALdVTlVSuFMlbfWKkPK/4G7dJO7v6ksuHc4M= 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=lVfUfguS; arc=none smtp.client-ip=209.85.221.50 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="lVfUfguS" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-44b729aa7c5so72168f8f.2 for ; Thu, 07 May 2026 09:28:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778171317; x=1778776117; 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=M8AL3Z61ICxzdlcnq6alkQAX3KWNxGv7zH8ZNYrPVpo=; b=lVfUfguSH0qvFJkCMkyL+uzlNWv2gvv5Pn3cMnn+SD43MCzfY26+/TYOYk5TAMJCXJ 4sH/7NJVIZ1RxEmEZA9+DVUG3pQaVWm4ukN3BaN+uIeHPfsvjliquQcdXIe5K8blKYtF hpJZAiklJFSWipxFUi89SEndZhgV2Oqkq1pZx3U24TwNgywzipIfrQIiJMADxC486UF4 l/b/iU8HlIRneli+ZQFr18f869+k3RiC+b/HFNPwOSLvzU2M2+G6Jii+kdR2mZPyCfRf rBBb+JlPVvJTcOmeqhfRqZJus4RyIiOPdYchEH1GWEb0aGMzcLY38iIWqS337h4nrJ99 WorA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778171317; x=1778776117; 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=M8AL3Z61ICxzdlcnq6alkQAX3KWNxGv7zH8ZNYrPVpo=; b=K5xUq6/wObRgHkD8pS+wiDLFF0cGRyVMqYK45gFj7gn0nBhZZLrfIF/R2Y7kxF+0iJ CTk4JDjZsWSrzQKIzv8aMNh3cdIksvSWUuvtDos2Egx6OZwWLJ445odWxvow/tnqMvx7 Y8zJL2jlWQsf2np86nGs7nBiO7tdLdnT79IkzWNaOGh3ciWoygctDHcHOtBwNMJ9UE6+ kDA33ktEeO5kP+BMOACm8t20g7t3yCbfkAvwJp1ZZApcjcbvUygG5reuz3w/42KnmSGK 7pKhK3PuF2kYHNf3hoxFJDtjFh7GYwyMx6KSKUkpw9bR728BDZAZbkHMLjtVDr0oluGr I1rA== X-Forwarded-Encrypted: i=1; AFNElJ9X0/HJrhDHY95ALQzKqXXzXuBJ5lTfqaa7gc5kixJ8Bldtkv7J7oRiTRBlC+y+njSszDWoC+Y9MDtSzYs=@vger.kernel.org X-Gm-Message-State: AOJu0YxEotWRvHw0kGnPJadRYHGWW5qoNKVwAcltcBYM6ERXeVdTHCRj WaE9oY9y/oRabLGHdOsucdrkc9U8L+o4xDWGVt+FMbWarvqkYTr7/Csg X-Gm-Gg: AeBDies7Fl40SG3wtYn1hrWzmwsAIcA77UQXgzV8UU7hn/KyfYeMaWXJfWnVapWy3Uz ksYK/ewLgZXqnYJcqJXEcHX2ImeYwq/+nbIHUc8DBvBBR9t9XRVewc3PE/HKfdSN/wl+xjqx4nk pCTAyS4EC7GNpHtZoQiWMhrynLdpbboYg0l9f6mWUE9aaqTc4wOWS0dCaKboBqvsDs/1ZOsd3qf 3Xp2OCn9SZQ1aQVDeJdam5wDVkB1DXJZVCX/8FmhR9b0QNglOpqOSqlu1gP66btX2/OTpbh177q P9/biCroXYgAqh97bmpUHA593wbtQfHwmmV+9AvSTNurZjWCuIjEHvJs5Vf2m6lyyTE1H0j7Mqs kUTBUQnwyTs3AzNgX4BJlbie276Pr/6ydtvB0bVSlbAzzuR658JZoNCWCD2bBr8pZxmArZcLKez EwutT68H4hsJnhIeatfskXU6ZRvbUzRACGLyuJ0Ef2SZYz1NY5qw2VrQg= X-Received: by 2002:a05:600c:4588:b0:48a:5302:8ed9 with SMTP id 5b1f17b1804b1-48e52f1574emr66634255e9.0.1778171316867; Thu, 07 May 2026 09:28:36 -0700 (PDT) Received: from localhost.localdomain ([94.158.58.131]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e53907e8asm131473185e9.13.2026.05.07.09.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 09:28:36 -0700 (PDT) From: Stepan Ionichev To: jic23@kernel.org Cc: m32285159@gmail.com, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stepan Ionichev Subject: [PATCH v2] iio: chemical: scd30: reject (response=NULL, size>0) in scd30_i2c_command() Date: Thu, 7 May 2026 20:28:00 +0500 Message-Id: <20260507152800.9062-1-sozdayvek@gmail.com> X-Mailer: git-send-email 2.33.0.windows.2 In-Reply-To: <20260506181533.409-1-sozdayvek@gmail.com> References: <20260506181533.409-1-sozdayvek@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 scd30_i2c_command() takes an opaque "response" buffer plus its size. At the start of the function the code already checks if response is NULL (via the rsp local), but the response-decoding loop after the i2c transfer always dereferences rsp without re-checking. With the current callers in scd30_core.c this is harmless, since write commands pass response=NULL together with size=0 (so the loop body is never entered). The (response=NULL, size>0) combination has no useful meaning: there is nowhere to put the bytes that come back from the chip. Treat it as an invalid argument and bail out at the top of the function with -EINVAL, instead of silently doing the i2c transfer and dereferencing a NULL pointer in the decode loop. smatch flagged the inconsistency: drivers/iio/chemical/scd30_i2c.c:104 scd30_i2c_command() error: we previously assumed rsp could be null (see line 77) No functional change for the existing callers, which only ever use (response=NULL, size=0) for writes and (response!=NULL, size>0) for reads. Signed-off-by: Stepan Ionichev --- v2: - Move the check to the top of the function and return -EINVAL on the (response=NULL, size>0) combination, as suggested by Jonathan Cameron. Drop the v1 "if (!rsp) return 0" deeper in the function. drivers/iio/chemical/scd30_i2c.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iio/chemical/scd30_i2c.c b/drivers/iio/chemical/scd30_i2c.c index 436df9c61..845c59a6b 100644 --- a/drivers/iio/chemical/scd30_i2c.c +++ b/drivers/iio/chemical/scd30_i2c.c @@ -71,6 +71,9 @@ static int scd30_i2c_command(struct scd30_state *state, enum scd30_cmd cmd, u16 int i, ret; char crc; + if (!response && size != 0) + return -EINVAL; + put_unaligned_be16(scd30_i2c_cmd_lookup_tbl[cmd], buf); i = 2; -- 2.43.0