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 3845814386B; Thu, 13 Jun 2024 11:42:12 +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=1718278932; cv=none; b=bcPVib/cjBOjRSNcES4WrkwuRNmEEmxYX5za5r3ZBekbZBz35/XpR5Y7HhzW+bQgTm9Ni/CXHpzTBgTUib90vX6JMV4k2e6oh/0NrhmDoaMgEe2XNaBXY4fJJCD/uo5StAEOkCY4BHWi8oNGvXRzzAUCEfvjWhwANb/ZHUpLiWc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718278932; c=relaxed/simple; bh=xEKIasH51cRz6lyTFIJ6JHyveXGQyKBrdfqAZTKb/34=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bC1zbHwRV18gb3fI0b6sFgNZzJ9KdB5xhIuUDq6I870o7q0R1TG/Q4FeDv06RwwA+6VigVot+NL2zqcXFLjOeRXPhakYFFuWi1kP6EX9GnV3kQ1NEqqOxGhM3u1KJ+Cv+75aMA3TWM+GgDoJ6tqfgkKZpu/YhWcgmbJOoi7FKAQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VLPYlw2z; 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="VLPYlw2z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5D47C2BBFC; Thu, 13 Jun 2024 11:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718278932; bh=xEKIasH51cRz6lyTFIJ6JHyveXGQyKBrdfqAZTKb/34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VLPYlw2zfrSqeWNJRLSeRpWB/S5sSd4V2tpOPYD5cOldtwokFWmyMzBqt/lKydu7U ZH+Sou9uUt5BX1oiYSCyMcYPw1Gec410YkhA2KLNyRS/+j6fy4ZbMr1V55qqb7BXP9 pjt4VXvK/f2xwHNw7Ecyw3bqeXFttTTE9waWhaf0= 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 4.19 088/213] greybus: lights: check return of get_channel_from_mode Date: Thu, 13 Jun 2024 13:32:16 +0200 Message-ID: <20240613113231.405731186@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240613113227.969123070@linuxfoundation.org> References: <20240613113227.969123070@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-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 8c5819d1e1abe..9dc51315f1fc6 100644 --- a/drivers/staging/greybus/light.c +++ b/drivers/staging/greybus/light.c @@ -149,6 +149,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); @@ -552,7 +555,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