From nobody Sun Feb 8 18:43:57 2026 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 EA37D35B147 for ; Thu, 8 Jan 2026 15:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767885183; cv=none; b=fi5PbNZzUKzToBguR3kRAmY8JNMHhVqG1YlS0CoGPfI4P5DeuEqghBzwbIT1z5DsQ05SjUFfjRy/D3VZf1dnVoXNIpvmjTpbVHelJoEYUgDbX+lwntHZzKmRFD1fQjaUnYLICUGg8yh8t+u+08NgmWBBebI1RAObW2aExGUycVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767885183; c=relaxed/simple; bh=96AtlZIH6oDSHa2on2bdBp8Q/kVE+BJcSB3ZEfpRh0U=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NV/4U7IuvZQxH3Jllh/0bZGPVsAs/CP4xRv5Av4NQivVTqxjTH4gtaEvA1OGZMfFGz2e48Z41HFG4hKM28Jfo5GD6o9j+/R9Y+ydfERc4kToKwYxp2F2w/+6lp8yltegK6XrPlUEFpCFe2234XY1kI+oqVev1JKGwNBJj9i++LI= 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=VZfp4SUa; arc=none smtp.client-ip=209.85.210.174 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="VZfp4SUa" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7f121c00dedso2879961b3a.0 for ; Thu, 08 Jan 2026 07:13:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767885181; x=1768489981; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=u9frDM5lhsIsOta1J2dC3heJ0BptFvIr5tuBxk7iS/w=; b=VZfp4SUaVSGwBX71I8h+ndtTxS1z5kdHwKiEet1SntGo8mV0HukU4az3iSwjgjVGKe b6ZK+l+MZhk2zHcdGSgt4feZhvtfQFeAetFnV7ecvcIyirlE6VZ7segfaxmY/N9jjs3O KCGWRw8dcfX2juYslqlJoOgnAviJijUmcW+jLjWsdxmNBzppolCT3/w23MYr9vs9PDG7 kVkfjJzPHHmD89ErGK8mTukKU53X0ATODYd82IPgZSilE+fXli2lv0+pxV6VnaCv+q8s aAi3ISfBLNTSFJ9Y39t3OHzw6qiklRiE9GzU9yMEom5VktBLR5/UK24x6lM9ZmmADuSG Dskw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767885181; x=1768489981; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=u9frDM5lhsIsOta1J2dC3heJ0BptFvIr5tuBxk7iS/w=; b=uwPEDkDUt/4xaHI6/wSoC3COH8JG6dc9rJnK5YIHZQ9ibFUiEJ7jPxw0940PZskeAg bJzU/MU0whXCxQnJvyDWJgMyJGnYlvAr3mwcbgmSx4uj2bP4l1N2dJtpTwQTJ9RsmF27 H6BnKF8/sUMN6JCaKplgAWxELf1uBMwFp9Y53K5E85Arp+EH6Qwu12zAQ3psbzeoUARK 5XVxUruXhTvHKLH0mx+6AuU/Ec1AcsMO2mv9idpgY/Uw02uZrKx2rWow+9BhfMSS4KIk s6rqAJQB95PEU2VzQcwzc3ROrtZUQMP0dM4KD363XJdydAdX7hHchhF9pucwXN8ixM1E b+cQ== X-Forwarded-Encrypted: i=1; AJvYcCXsCXI8sGGV9yWj15Awd8zKNq/SDrtbHGrZ8XudZGrp0/rpq/3TkJ+3/en7tnbyRwBBTfQahnNCy4+7eUI=@vger.kernel.org X-Gm-Message-State: AOJu0YypT12W1uhOa3HVtgB5/ZzXww8mStv1f08bF4QinJXLTOlptwAY uyZN3Udp/2Yz5TsN+Sur0Bro1aOWBg0oSiUztnDTMGC70Ee9tVZMtlLA X-Gm-Gg: AY/fxX4pZ5bdNu0WrtsDkRIAvX5Dbizq59YzXpzUSS7b5HYGqZLSz5LgxPOw2ln5oK8 6Me5/rqTGyDuEhNbWrr37ei8Nr70u+eii6FFZtvGq7avC3gqeNwxzdyrolJkKBiJSPnktzocYvz by5IwnoujjQGKrHoE9/NW2IOjg6KVfFOmyAsBbluuqc7wTpUafZRRkVYSaFAc+smcn2yIkeSVbE NYbUkA43JnOTBUk6VeqkWvEdVQpfez40WfkfnBCEs9hTR0hEmZOw7xtAAGgj48tbWeH1AbfQQ3Z /xXDJrP1dxBK+hclIb/vo8pdDSFQnhS/BpBu/r+VDpJsnOOq9zfj8uMoNUw9AEA0Lmp6M/7/M54 sHZydvg4NAgAGPctaiEEA4yhp8D35aiPY8hMTSCrG9OjPqIe+LkK7lHlZqwbYjYeVOBmgVu624F Gz1FmztvZ182HUdkIvj+1KUZQWoEPx1CUONWrh+BLRKFQgay6jcBz+CCGSfSA= X-Google-Smtp-Source: AGHT+IEzA/mL+RgRg1Lb+6pXizfwPfga2Mz5SLJjfBB2pKPQSloH1grWX2Sz4faegTP/rpZLUzZR7g== X-Received: by 2002:a05:6a20:3ca7:b0:364:1425:8099 with SMTP id adf61e73a8af0-3898f905cccmr6190413637.24.1767885181241; Thu, 08 Jan 2026 07:13:01 -0800 (PST) Received: from localhost.localdomain ([2409:40e3:44:c9c0:8d34:cc3d:a8c9:1a48]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c4cbf28f6cdsm8188087a12.6.2026.01.08.07.12.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Jan 2026 07:13:00 -0800 (PST) From: Chaitanya Mishra To: rmfrfs@gmail.com, johan@kernel.org, elder@kernel.org, gregkh@linuxfoundation.org Cc: greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Chaitanya Mishra , Rui Miguel Silva Subject: [PATCH v4] staging: greybus: lights: avoid NULL deref Date: Thu, 8 Jan 2026 20:42:54 +0530 Message-ID: <20260108151254.81553-1-chaitanyamishra.ai@gmail.com> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" gb_lights_light_config() stores channel_count before allocating the channels array. If kcalloc() fails, gb_lights_release() iterates the non-zero count and dereferences light->channels, which is NULL. Allocate channels first and only then publish channels_count so the cleanup path can't walk a NULL pointer. Fixes: 2870b52bae4c ("greybus: lights: add lights implementation") Link: https://lore.kernel.org/all/20260108103700.15384-1-chaitanyamishra.ai= @gmail.com/ Reviewed-by: Rui Miguel Silva Signed-off-by: Chaitanya Mishra --- Changes in v4: - Add Link to v1 and carry Reviewed-by. - Tested: make defconfig, make modules_prepare, make M=3Ddrivers/staging/gr= eybus/ modules (AWS EC2 eu-central-2, Amazon Linux 2023 x86_64). Changes in v3: - Add version changelog below the --- line (no code changes). drivers/staging/greybus/light.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/ligh= t.c index e509fdc715db..38c233a706c4 100644 --- a/drivers/staging/greybus/light.c +++ b/drivers/staging/greybus/light.c @@ -1008,14 +1008,18 @@ static int gb_lights_light_config(struct gb_lights = *glights, u8 id) if (!strlen(conf.name)) return -EINVAL; =20 - light->channels_count =3D conf.channel_count; light->name =3D kstrndup(conf.name, NAMES_MAX, GFP_KERNEL); if (!light->name) return -ENOMEM; - light->channels =3D kcalloc(light->channels_count, + light->channels =3D kcalloc(conf.channel_count, sizeof(struct gb_channel), GFP_KERNEL); if (!light->channels) return -ENOMEM; + /* + * Publish channels_count only after channels allocation so cleanup + * doesn't walk a NULL channels pointer on allocation failure. + */ + light->channels_count =3D conf.channel_count; =20 /* First we collect all the configurations for all channels */ for (i =3D 0; i < light->channels_count; i++) { --=20 2.50.1 (Apple Git-155)