From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 061A619D069; Thu, 6 Jun 2024 14:17:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717683450; cv=none; b=TSFw3HE2Eoj/3KaUH0BQxUi1gPT0zEkURalCvDsH9AI/+0nFBfh/w5DPRGFx++vRBRFcxY/2kjuJQBNBjbZ0sByoSv4kD1ToXmnTbI6ECdcmSl+Y2fUSt2CKwP3ZtCHPiITsCrNjfwKGgu6y5fqTbLnUdGaM0joRrlttwbGAV9s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717683450; c=relaxed/simple; bh=htlYTaaDum0TLXLQxbqgARYDTnxuqjdmkHgW3DYZBsw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ij+tGPjeDnk6nvAMjg+buwrjYSsw2+1w2JBc03tbQbAMXU7fkcyuZPh+Oltcl1+/mUTuaIwOYhoRuJ+unDVw624XSG0uoh1b+pNsOGUga4DP9XhWmVHP8QnIWvWGwceSzLqjj1YDVO165f/XrtNU6oXjWhDfTlJhX4LVfUcZoyw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=s64NPFEs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="s64NPFEs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7EFCC2BD10; Thu, 6 Jun 2024 14:17:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1717683449; bh=htlYTaaDum0TLXLQxbqgARYDTnxuqjdmkHgW3DYZBsw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s64NPFEs7ti6nw0yeuZYPoCddi1dm9w/r7KdUEU+FPb7KUr0DvBo/nA2syQ+C20G8 WdfTgEac8Xx8Vt0dyl/G+DcB3XuLtC5its1Pw5NsmMS7AcPZCLrS9JfnGzN02F4Go0 KUTgE+qqApUgzYVBZeqZomMP5OJ2rSbG7liKUong= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mikhail Lobanov , Alex Elder , Rui Miguel Silva , Sasha Levin Subject: [PATCH 6.6 393/744] greybus: lights: check return of get_channel_from_mode Date: Thu, 6 Jun 2024 16:01:05 +0200 Message-ID: <20240606131745.065880547@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240606131732.440653204@linuxfoundation.org> References: <20240606131732.440653204@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rui Miguel Silva [ Upstream commit a1ba19a1ae7cd1e324685ded4ab563e78fe68648 ] If channel for the given node is not found we return null from get_channel_from_mode. Make sure we validate the return pointer before using it in two of the missing places. This was originally reported in [0]: Found by Linux Verification Center (linuxtesting.org) with SVACE. [0] https://lore.kernel.org/all/20240301190425.120605-1-m.lobanov@rosalinux.ru Fixes: 2870b52bae4c ("greybus: lights: add lights implementation") Reported-by: Mikhail Lobanov Suggested-by: Mikhail Lobanov Suggested-by: Alex Elder Signed-off-by: Rui Miguel Silva Link: https://lore.kernel.org/r/20240325221549.2185265-1-rmfrfs@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/greybus/light.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c index c6bd86a5335ab..9999f84016992 100644 --- a/drivers/staging/greybus/light.c +++ b/drivers/staging/greybus/light.c @@ -147,6 +147,9 @@ static int __gb_lights_flash_brightness_set(struct gb_channel *channel) channel = get_channel_from_mode(channel->light, GB_CHANNEL_MODE_TORCH); + if (!channel) + return -EINVAL; + /* For not flash we need to convert brightness to intensity */ intensity = channel->intensity_uA.min + (channel->intensity_uA.step * channel->led->brightness); @@ -549,7 +552,10 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) } channel_flash = get_channel_from_mode(light, GB_CHANNEL_MODE_FLASH); - WARN_ON(!channel_flash); + if (!channel_flash) { + dev_err(dev, "failed to get flash channel from mode\n"); + return -EINVAL; + } fled = &channel_flash->fled; -- 2.43.0