From nobody Sun Feb 8 07:26:48 2026 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 946ED4218B1 for ; Thu, 8 Jan 2026 10:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767869408; cv=none; b=WSrfor1CC433SHNHsLuRCOE0TT0QJ/NrTORpl6E6oAf9beYgZHGdnQF2npUDVTOiulSzaFE3maYrROcd67KhNadFexKeJu0fHwwoz6ATMgiSMsX7472Lz/u7FzzYU2ZBokHL81RkNpZ2hvF8xy89hhdsyoan/gf0WfAAuCdIZ/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767869408; c=relaxed/simple; bh=jT9R8bu7GP8nj1D0asBMoFKBtBgk7PmQ/JQfCIlQENk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EsWbFrvw9y3SpM/0VPF+tYUvUfJvacFSBRpQf0XduZwB9nOmXjVtA4eHpl9rLca5ZtCscUfu6PDUGQeUc/GtxWwxEXo+EMu9sDTa0OEqbwyjrWA6L+x+35poKtEQ+Dz21zqxA7OL1SOXLEoqI2gHKdeV6W5emp4KrOg/pPX3i0o= 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=B2X2NHpv; arc=none smtp.client-ip=209.85.215.170 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="B2X2NHpv" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-c2af7d09533so1934914a12.1 for ; Thu, 08 Jan 2026 02:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767869399; x=1768474199; 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=EjN6KRy96rZIFzVOVO0pR3xnbF0qB/QSbEh6qKIJyEw=; b=B2X2NHpvEWdFPL38lOWLQ0aAg7N9CHgjPGxSJjJhbYIe+/cI2gYW/pBM0AA7gH3Fj6 9dGBGNtevvXZr9eSLrHiX2r104m/rl92PqG60md+UNvklRd1F/rTn8q3R5/lXd4Q/nBd ++cZnqAp7Cm5bEjcwxwL5P7zqLyLGRGsW83asZi80clPUBbKxA+cm3zPOyEcta2geZwZ bPTn5Fma9AJMz6h5BdgHPSRB0x6/3WUKACrOES/EiuViD5IpXk1cF+ZpJ+5PDRmbysqu uqoytbE8+bPlCK7bn8hT9JZvYdlE5vivoZgrYLVlNjn7Ja1/7AKvH6F8Mq+9oqIBx8Zw cNIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767869399; x=1768474199; 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=EjN6KRy96rZIFzVOVO0pR3xnbF0qB/QSbEh6qKIJyEw=; b=wPMsWQTp6qpyESywfnNU+OL+bVjlmP82CV31DLK4LWLKJ3ncHj+x/dHsFKBeiAxrUW R/c+gqVEgze/dLfdWZxThsPqmHAwBRyfpnu0P0l+yTrVa67m6YSiaZdFovk3c+65bW/T cmGn/TYP4OLT/gBkL8SVSe/HFyqYDeZRipA5PA4Ir5k9Z4Klckf4niHkbjXjeQdKa4fP r6Gh0sc6duSqJIT3JTRfsToXGVoVIXEllvzTvJxZ7uai6oNbNLtuHtIxiO/mB5+KA75Y spUPlgGqgWJGEBKlceh/RYeQyg5cl0n6oyTb3n0fRPAhoCugKG8Ts/BIA4IEIrC++MQe G2WA== X-Forwarded-Encrypted: i=1; AJvYcCVaQJvMz4gMCdLj94iQVJAM5P6ZV3BgkMIJ2EAqJMSMMtUAXBoyQe9bh3pkRUglZwdHAMwk9VnQWPiLWQY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5eOGoS4mB5jLfRLlHyCuNPBeO400yUbvEvgmNjW9jmU6liDM3 ime17OuuFYIS2X5zI48g9PSg5PelvK0jt/w0FnEnj3XNYm+9cYJhunxA X-Gm-Gg: AY/fxX7XgPZAEr45QIwkqa6SDtFyHvgBYuGiQ6EABP0ACl6QUtXt0/WO6NY4u9cCYkV d9tQPFvhj7qxUMAAsSD+4KFLsNh3nnMAV6DC4r8xuk9abJ/UrTH3AE854LAThx4iuB27ATrXPsC sP3L1N04N4yh9jLY8y+3bGrbGMLemyg1XNNrIXTbOWtFyERE9lhAGikrxpv7IPri/ZAHTxl147K z3Ktgmdn/5lST37ivn4hqn5VmomRfq+ZkNJmRsJO2YfT//oKlPJbYzpDT8fkmv706fLXFnZMcGr fgGX8z2SLi9uHCWCIAtjJOVERdGO6M+qcByiFrr+SozwzbTe4YTBWpv88/mHqmej2ewyRMy5GH6 qKeOiEm/7iEwz66482qfmq2CMCS5ktPBtHokiQhXI6JaIKIK/EnYpKo2HQgXxnvyxzDjqV1nmDE nfRdm+7hDtfcRgRth6IecIHf1sAxz3y7lojEFc4HLWsb5mO232/xmVL2Lu+9L+TdvzHp8V7w== X-Google-Smtp-Source: AGHT+IEJg51776qmQRAec7r8Q56/vKAE9mkMRebfFBTyZn5YX2SzdAZ6YmZhM3qPZ58Jcn4GN6R1tg== X-Received: by 2002:a17:90b:5211:b0:34a:b8e0:dd59 with SMTP id 98e67ed59e1d1-34f68b9a218mr5550827a91.15.1767869399399; Thu, 08 Jan 2026 02:49:59 -0800 (PST) Received: from localhost.localdomain ([2409:40e3:44:c9c0:8d34:cc3d:a8c9:1a48]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-819baa192b3sm7391855b3a.11.2026.01.08.02.49.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Jan 2026 02:49:59 -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 v2] staging: greybus: lights: avoid NULL deref Date: Thu, 8 Jan 2026 16:19:47 +0530 Message-ID: <20260108104947.23767-1-chaitanyamishra.ai@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260108103700.15384-1-chaitanyamishra.ai@gmail.com> References: <20260108103700.15384-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 Reviewed-by: Rui Miguel Silva --- 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)