From nobody Sun Feb 8 15:25:40 2026 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 B24F33E95B0 for ; Thu, 8 Jan 2026 11:07:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767870484; cv=none; b=aZLPyP8lwLX7j4vy6bjjXccs+a8IncyEhyhV3lZv/256dzJmv5DIOd2SfwjTHWHs+NVYsHFdUW5ufacOwwmyXiUS93qmiaddReTjjZzZFeVv/HNHqZDmmv+d40tDtAT0k9qsgW30oYjt4w68GQVDSzQefgy+Dqg1geStulAnz6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767870484; c=relaxed/simple; bh=VF1Jmsv+ZJKjPzQoy/kwUmvilAG6QCYrQFJ7oGULPrA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n3HftFgrOCrgKnlwKFrZNA6oajCBX/VYsiefcVbMov0CoZinBYIjBjgQ8PuBLqLWQp6FAdNDmmFlcFdZAQ4qZcjGJ9mE1Ax9GeXeJHOwDJyvA85sgBHS8PCXDSnYR3sl+eGvIJ7AzdYmNjCqK2HHSHMUpSDhR8eihjJKcfTO5g0= 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=IWyPfzg3; arc=none smtp.client-ip=209.85.216.41 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="IWyPfzg3" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-34c2f52585fso2057411a91.1 for ; Thu, 08 Jan 2026 03:07:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767870478; x=1768475278; 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=ovFL0ZgJ05PmQmmqASFpLTQJxg5CpaLFBPgcpKVwojw=; b=IWyPfzg3m5rxNZm9RgI1VbVyQka+yTY40uvKgYZ2FbRC854crgqJ9J3ZyLqD9FRi/1 Oxj+ytPmY1xWRkXVTvpytKkcfWLqVg+VOfIlwONFIBVnq2O4Uw+GYPQAJjgLmpD7OK1n oLx7VNqOjXPqbFri4HOToW73qbl1F52L/SkYUQ19mRFSrm20UKVmJz1bsKzErlS+fH+S RCh7UTOoHvi4DIZgK4KRdst/2PZRazW645xFZfOTtVepJlCbGJ+8tf6BxZFzM31CP6iS Q5L33W0a6n7hhsX8deKHc5dsZh6S4jg8SfWWu9VUvjhaovhLyNyXQ7z9psJc3S1/zZLo cVgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767870478; x=1768475278; 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=ovFL0ZgJ05PmQmmqASFpLTQJxg5CpaLFBPgcpKVwojw=; b=MhK2V0QrUN1wQUHBI3VYPQ33e6hTaakCuuQ7qiiMzsSAELMa46KgFt0JZoHCNl1ibz sOdVw0GXl9bv/+undeVniMzIaR+WU9wCglRMvwzFq9V6K2bhoszuqtZT7LugbqbrSVa7 4CILOg6+nuFAMZoHYywPfIzvOAGTIoHf2u9CU9uqAt9SZRn24aInmZx7DgBBvmLWUHzo OQ/DQA5d98yhRZs3FUZuBMpcU2ODgcpam1PmiofDnzscVDT0crF3XpDTQw1tXObBl96m iROiyFF+VBqj3rj6SsXCHpUP4iNRuXf3y3I007AoCHgOGSfhGvscs1VGlB+WXNT/JaWx S/aA== X-Forwarded-Encrypted: i=1; AJvYcCV4BhBzsRm+fOOYcBAnOa0yzKmQ2TnhO4FBQ+E46WXYRAYoORartKej0M0aOp0CpHjJvmfEc4XgHR8S1AE=@vger.kernel.org X-Gm-Message-State: AOJu0YzvVefysXDqQsbuuyhChtUgoCpvhB5e4yHix2BF0IQMEFRrgzzd x5uVdGkWurBBxny8DGwdBpLeg2yigleuPC8gRbO+dpF0RydU5QvLwwFg X-Gm-Gg: AY/fxX4+HCAbJjyGGTlwNiv+D/xUmnUX/0cdU/mhmZQlLt20++FdRv90aOKcw7KL9LI Q2FzMQQfO/gYsOs2VIKe0Y6u6lF+FMWQfhNL4GQHi/je31G2HrG+2ByFLgnMm7LUq+Y4LI7idLC +inHnznLcQI8sd5VKYQZKnZxkdwNA+hRK0JjMsj5QaeD5PoDmz82g9Ghcl0jYyttoL2m3RZyY+x GIi4BY+HN3kRWlot54t86xknS6Qi1pyO0Jw1kMbGnI8xV1nZ9SJ8Me7PXk7q9vDNYz+qAEWlqwI avy6CMXI8t1z0e+HVysHt5rmc6meFWh70x1rxS36abZ63tSye1n0234MQ8HmCOFjLx6aqJHew5H rldCpj02zf59+/KlxPwHT1N/YDmT9F5fSLZPWKgr9uw+3zoAsDGg+dHJLIxJdxEZm9OAo91yiFS JK13SFX3G2F3Zf+JJY9UH+Ec8SG2QFqKzWjxVuPZClGE/zIYmEDSgDc/dqJgk= X-Google-Smtp-Source: AGHT+IEZGNq/qjuxwRs95G5htBzgGzwouoNNR9bUa0QHpgSKCZ7OD2+N2vgHG9VLs/ENE1zoFdn6zg== X-Received: by 2002:a17:90b:1802:b0:34c:a015:9cb0 with SMTP id 98e67ed59e1d1-34f68c91343mr5167636a91.22.1767870477529; Thu, 08 Jan 2026 03:07:57 -0800 (PST) Received: from localhost.localdomain ([2409:40e3:44:c9c0:8d34:cc3d:a8c9:1a48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34f5f84ef1dsm7712096a91.0.2026.01.08.03.07.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Jan 2026 03:07:57 -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, chaitanyamishra.ai@gmail.com Subject: [PATCH v3] staging: greybus: lights: avoid NULL deref Date: Thu, 8 Jan 2026 16:37:43 +0530 Message-ID: <20260108110743.28579-1-chaitanyamishra.ai@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260108104947.23767-1-chaitanyamishra.ai@gmail.com> References: <20260108104947.23767-1-chaitanyamishra.ai@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: 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") Signed-off-by: Chaitanya Mishra --- 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)