From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.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 97E1B492F0D for ; Thu, 8 Jan 2026 11:05:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767870324; cv=none; b=G0/taf/oCRO0aA/FOADXzaOlmJhVOiHfXl6cLuvmVwvEeIlZOnOVsIMjz3gqiSugYaGwWvsS/M59930t3v0pXlPljw4Grrdb4LGfrXJ/gB6HPa2Py+AcY23bSA+i89kgdjeu8wVdUO/pXwx020BW+/QwXWRE/OhM0zGCElPtZKg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767870324; c=relaxed/simple; bh=Y8yjqHqG57G3fx5nuEBV+XOYIn6MXJdwPT1PCD1Iuso=; h=From:Mime-Version:Content-Type:Date:Message-Id:To:Cc:Subject: References:In-Reply-To; b=QxDLLIHXIQGePMG8bpBoB/2rUia5knBo2eRzT7np+IVY0TLNNhOW1aZfj5k4y0fzliPkTm5ij8GaGxaMyI+Cqf2rYysyy7LaWECBRoQpL9lZUQPQkP7oMjRZ63MzkutDpTvTpcdGWROpij/hcBLHUj8mJJZT5lhsZMBuwCGVY8g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Sw2b5TS6; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Sw2b5TS6" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-477619f8ae5so24374445e9.3 for ; Thu, 08 Jan 2026 03:05:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1767870312; x=1768475112; darn=vger.kernel.org; h=in-reply-to:references:subject:cc:to:message-id:date :content-transfer-encoding:mime-version:from:from:to:cc:subject:date :message-id:reply-to; bh=7wi0cLxVYTkjjMZXxZy4zeQFvgVDMeogFnmSnZc8m8I=; b=Sw2b5TS6agHRKyLlvF55RUVEkpLb7aW3cM37f8ret8HQALxuAvwCoEd6qOVJNuLWLn tHHUPEqw8mhBkqebTGk6FBwzB7+ptvxHBr4v1C6aaWi3RnBTSN8NY4inmtJ79JNqrwb/ VJII+BI7vG5b/ZOVzx/GgKgr+cKPrEHbY8t9TLRct5X6oidBuKfdVxb3dyadcSiX6kTp 6DYiiTC1fDbJQ+mB+Vj7uZBDJhfWhslzRIMSoDXaVgrjmUJyfcf3bfkk+sb7HDCrwbdG 32a0g89Wx7DX0fBUSQkc93DEXQEYmAQqMMt1WwFcQOdxTfQAyQgP90KkwjvhEul9h81E dkjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767870312; x=1768475112; h=in-reply-to:references:subject:cc:to:message-id:date :content-transfer-encoding:mime-version:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7wi0cLxVYTkjjMZXxZy4zeQFvgVDMeogFnmSnZc8m8I=; b=B+DxgxSWUzE2MhbIbkIHPty2wzsDQPYy2wxzhzFpiFvw1TpNybfGGz1wa/zcel+D+E suT3K94gMZyG+dbRMZm2Da183iu6BeIZpqO5NznnD8xNViSUslFesEB8Nnuza6AA/Kez lyLjWPiwWIGQhP2SVEDkhvl+9U0mlnci7ZhEHfs1qLWmz2uoPmApk55kSSiMh7+JOSSq boU4DWEb10/7uedcxu3iuEeEf+F+8wIBKR+sDxMBtkFcULhHivVhWYS2X4fn2Rc42m9t jxQz0hZ517ubWWVCSgELR2OOxzECtP+hShslB42Sq+6CNEJBKerzwwCBDVPMs/0jHlLY whMA== X-Forwarded-Encrypted: i=1; AJvYcCVfpHpIEwyIm7M+5btB0pxKCINr7KiX1bG33P/jKrxmr2Yp8hFa2E4MI+YrH+sToC2XinzOZQDtlBRR5ME=@vger.kernel.org X-Gm-Message-State: AOJu0YwOekjxI+fZymvbSjgmjJHb4FhpDyuL7pptQk+oj7xHyvnRujdf n1yTWcvlochexy1qW92cXqRZmdBKizTBeYpmmHa89wn3qx0WwPCQZBT3eytQq8RbrJM= X-Gm-Gg: AY/fxX5CUPPLml2wlWKt9O0yDW09W812xR7TdLxEOvnE/vUNMAgK5wEd63DRqYgSB9b kkc0bBGwRvpiCSKjvRWRigON925csUqzVWq7GR5JiI49xwgi/YUTVPNgdmRS+lnuf95SLx3rQBe CXkOly4jP7TGRHPaNdnpCM1YYFLAdu11Enxkk0C398o4PL+L975apiKMYKNFSdIBl1/31XV1Uvl iN1KdADmkt91fTyM4LzgL6pXNceAxD1NE8fxV8kXdW66fBDNbYjNMsgYhHZq17iJlCR5SXc48/2 +PJQ8Mj6HDBgf7FUVr1Bz0+pSRPFU2Rq/Sy6J4NMxYsYRZ9LQOAQl68BSbOcSD8RRWnoWiIFTnF vtSPGwiGNuVAa8EGz3IOxLRgJUmJjBxSfSVRl3mEzgL0XUbaY/6FPMogqNlu9mO9LgIwYPBJcpV PZp63ABic1qMHZ+MiNpQH8gI37pncVjXlYd2suMmWm8OFuGNM4Fcqa X-Google-Smtp-Source: AGHT+IHv7g9k/MI4TfuXMCEZW93m6zGf7qxNLrOVEx9WLQYfZAR+01N633qUWhbfiDUgojUqOvYRPg== X-Received: by 2002:a05:600c:46cb:b0:47a:810f:1d06 with SMTP id 5b1f17b1804b1-47d84b26da4mr67559795e9.4.1767870312264; Thu, 08 Jan 2026 03:05:12 -0800 (PST) Received: from localhost (a109-48-201-233.cpe.netcabo.pt. [109.48.201.233]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47d8636cb0dsm41520205e9.0.2026.01.08.03.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jan 2026 03:05:12 -0800 (PST) From: Rui Miguel Silva X-Google-Original-From: "Rui Miguel Silva" 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 Date: Thu, 08 Jan 2026 11:05:09 +0000 Message-Id: To: "Chaitanya Mishra" , , , , Cc: , , Subject: Re: [PATCH v2] staging: greybus: lights: avoid NULL deref References: <20260108103700.15384-1-chaitanyamishra.ai@gmail.com> <20260108104947.23767-1-chaitanyamishra.ai@gmail.com> In-Reply-To: <20260108104947.23767-1-chaitanyamishra.ai@gmail.com> Hey Chaitanya, Thanks for the patch. On Thu Jan 8, 2026 at 10:49 AM WET, Chaitanya Mishra wrote: > 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. Good catch, going through the error path, does looks this fix the issue. But you need to add the changes between versions bellow -- and maybe a link to the first version. Reviewed-by: Rui Miguel Silva Cheers, Rui > > Fixes: 2870b52bae4c ("greybus: lights: add lights implementation") > Signed-off-by: Chaitanya Mishra > --- > 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/li= ght.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_light= s *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)