Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp912983lqg; Sat, 2 Mar 2024 06:57:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU2z9h5YPiusquRqav625Av2EuN9WOp4nx2ziczUtaj1fCxOzHI4uDpweW/YccSd9+fYwfW8afsRknOGt1gkGLuwHrun7GyODvu7ZWeyQ== X-Google-Smtp-Source: AGHT+IGipSYRtEck/ChWdI72cPQ00BE/ZHn9gN5mTSd6HzIrnOq1yd10FnI7jSBy0dhkLHjT0pmS X-Received: by 2002:a17:902:7449:b0:1db:ed09:db98 with SMTP id e9-20020a170902744900b001dbed09db98mr9443510plt.12.1709391448505; Sat, 02 Mar 2024 06:57:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709391448; cv=pass; d=google.com; s=arc-20160816; b=WFKWfsVsdjY+EuG6X/al7kxuwAB5E43epkKofzCbOSMnCkD0Knxwm7OsWB17uOEkFD ICFoQ6TfWWGVpr0K1075TmGyKWar1NkTkFledYu5KeTY+mz31fRwJKxde6pTPeNR4ocK BUmpvB7UQCD89SV5VsbjilDwF9sdB3+UxXPsmUkr/usb9YbF3eLkmLpm29LDgh8Nf00K yjCbrmBidlgjD99jFAmfobYTyCvGXQsj4jVqLqvLq6ZkOk51Tu5upAlK2EFZ5qVrBrN0 o8PDxRQ3sgXfQ2F7YEslg8NhrcsQys5kXmhE9dzn3w4Yb1Z1mi988EvyhcAb8TTms2Qp wKUA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=wfIgoTdA9N+MeIiEy0xWNsxv5l2fuvtP53bPZ++Mceg=; fh=jFBs2SW3lekWP4O1iJS8JDAVbcfjpiAcvRBDo5WzNTk=; b=L5pYpuqjTfmAs9of+5qPNEwihTXmaRULqU9QsUFTQB/KNGviZ9zPlA9vFOxMPPGWV4 uCaVDbm+ePkkMzMWpzla4fPEj8K951ECYbFkDPGC+qiNJ9+rGz1GvGTcdsxpfkz3YY8q CobyeehkWnT2TtYIPYV6COOK3H3rVttyUtm6mWkiB7mnuWAzXU1S5QNJ633CrD2E02JP olnXrAlQgODWjstbNAhmNg7qM/Q0fACilJa47HbKcxs8vkVXb5ret5H2yaChWvQIUuIj 7+iJkW710q/afXBE9aZptcsx48EvMH99+eJ3apn+GAbu3f55dxlfw99Y7UmyRjM6soSG zqdA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ieee.org header.s=google header.b=Lv79n+GI; arc=pass (i=1 spf=pass spfdomain=ieee.org dkim=pass dkdomain=ieee.org dmarc=pass fromdomain=ieee.org); spf=pass (google.com: domain of linux-kernel+bounces-89466-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89466-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ieee.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e12-20020a170902cf4c00b001dcdfbb0007si4889077plg.46.2024.03.02.06.57.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Mar 2024 06:57:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89466-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ieee.org header.s=google header.b=Lv79n+GI; arc=pass (i=1 spf=pass spfdomain=ieee.org dkim=pass dkdomain=ieee.org dmarc=pass fromdomain=ieee.org); spf=pass (google.com: domain of linux-kernel+bounces-89466-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89466-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ieee.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 143042836FE for ; Sat, 2 Mar 2024 14:57:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3E5517C66; Sat, 2 Mar 2024 14:57:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ieee.org header.i=@ieee.org header.b="Lv79n+GI" Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (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 8A57D17BA2 for ; Sat, 2 Mar 2024 14:57:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709391442; cv=none; b=Hgkzs+D48iSNPDeNlcvxNQUz2jy4fBKQsdpistF9AXeBVCltFrQUWeM+0bVVzBQpERA/NjtARJG3dyGqahsKWuo4DvcawOymQVHUyd7CqkKUuUz+zAPVT5szOLkv3KsQMSzMWEZetOb/9u8ruIYKxmwpS/VORvgXmF1THkWnNfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709391442; c=relaxed/simple; bh=vsDO370P9L0eb7fcWgulrtTqYp1omUqwzrlkY+TsrEw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=NNhUYGLx5uO4rM8Ssmh07Wn18Nf2T5Ly4uG4Vosd7mk/73B8uk77tklp16jWD2SYpPjBzFBrnWRFwRBaLF4ZMf48ozTer09A6oBq1Iyyjci9pW85kOm8Yo4SiFF6Fci83NxQPvVoNKZMFDJtoeyIzWvAuKTqkwugiLRg3b6d/Ow= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ieee.org; spf=pass smtp.mailfrom=ieee.org; dkim=pass (1024-bit key) header.d=ieee.org header.i=@ieee.org header.b=Lv79n+GI; arc=none smtp.client-ip=209.85.219.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ieee.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ieee.org Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-6905d51fdfbso9742776d6.0 for ; Sat, 02 Mar 2024 06:57:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ieee.org; s=google; t=1709391438; x=1709996238; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=wfIgoTdA9N+MeIiEy0xWNsxv5l2fuvtP53bPZ++Mceg=; b=Lv79n+GIukZYNqW1yCfnmacMqZztGlrqCYXSwWvvghpWzeYdvbqeVPIjwy8U1+UEIU 1spN8WqMdkyDUTg//9erJCwQZ9AdfixlaejrMNJYpDeMhaEgkWHzh11uOEiyDKu9cv0C 8d6baKt65vEglCpqT7adkjYN5CKrZW5CWZVtM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709391438; x=1709996238; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wfIgoTdA9N+MeIiEy0xWNsxv5l2fuvtP53bPZ++Mceg=; b=Ql5FxwekMGSjdQs/BPj8lqe0FdF3d+zQAgRoMshQcps8p3NUGR16J77BK5cTJCzHZ5 lsd465UM07Gu/8k1NfuVnauaJkSg1DXjtsJAHE8AEV2AnLhW+U/Wj7W9iWK/IBrMBmAO GJAO8y7Zr0rw+4RyfCR15LaUBBDj9cQ47mGDMro617Q7MSoUhDpagFTJM09EhJyr0L6W wHSv6GpKyXfmXzIa6O6QA+flS2X1+KbEmOXNjIOUazqeYCPKzw+qk8Z6zyrkF0ghaXDM pqqO70cMlRkC0XQIj0rGF5peB6O1ZqDDw+luP1iFPXGDsat0Ex6juHtN8NEEGsAbjtjw jFEA== X-Forwarded-Encrypted: i=1; AJvYcCW9AmxQUiikuBq444IoFe7F2NpuyXl66hB2/3kKW2s/jnbSQ5UVam7ziWsDH93j35dlUlkq1YTWKe0wpwb7DOteX2bMCgMXnz/YyNV1 X-Gm-Message-State: AOJu0Yw+OGcKVzXV7+MzMV2uKOQo8eMppI7KJyEjNDQG8kW/j/og6G2o Ta1zpI6ijx5KU2km+8jPYkRUnNcvd9YnYJSyoLxPjb1YkJLu+IJ0/xGCOkriRQ== X-Received: by 2002:a0c:da84:0:b0:690:5ff8:cc0 with SMTP id z4-20020a0cda84000000b006905ff80cc0mr2942320qvj.11.1709391438501; Sat, 02 Mar 2024 06:57:18 -0800 (PST) Received: from [10.211.55.3] (c-73-228-159-35.hsd1.mn.comcast.net. [73.228.159.35]) by smtp.googlemail.com with ESMTPSA id or33-20020a05621446a100b0068f455083fbsm3018169qvb.63.2024.03.02.06.57.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Mar 2024 06:57:18 -0800 (PST) Message-ID: <36a4d208-9945-4a65-bdf1-d8309d779e63@ieee.org> Date: Sat, 2 Mar 2024 08:57:17 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [greybus-dev] Re: [PATCH] greybus: Fix deref of NULL in __gb_lights_flash_brightness_set Content-Language: en-US To: Dan Carpenter , Mikhail Lobanov , rmfrfs@gmail.com Cc: greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org References: <20240301190425.120605-1-m.lobanov@rosalinux.ru> <7ef732ad-a50f-4cf5-8322-376f42eb051b@moroto.mountain> From: Alex Elder In-Reply-To: <7ef732ad-a50f-4cf5-8322-376f42eb051b@moroto.mountain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 3/2/24 3:59 AM, Dan Carpenter wrote: > On Fri, Mar 01, 2024 at 02:04:24PM -0500, Mikhail Lobanov wrote: >> Dereference of null pointer in the __gb_lights_flash_brightness_set function. >> Assigning the channel the result of executing the get_channel_from_mode function >> without checking for NULL may result in an error. > > get_channel_from_mode() can only return NULL when light->channels_count > is zero. > > Although get_channel_from_mode() seems buggy to me. If it can't > find the correct mode, it just returns the last channel. So potentially > it should be made to return NULL. I agree with you. This looks quite wrong to me, and I like your fix, *except* there is also no need to check whether the channel pointer is null inside the loop. It's the address of an object, and will always be non-null. static struct gb_channel * get_channel_from_mode(struct gb_light *light, u32 mode) { struct gb_channel *channel; u32 i; for (i = 0; i < light->channels_count; i++) { channel = &light->channels[i]; if (channel->mode == mode) return channel; } return NULL; } Rui, could you please confirm what Dan says (and his proposed change) was your intention? If so (and assuming you also fix the check for a null channel pointer inside the loop): Reviewed-by: Alex Elder -Alex > > diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c > index d62f97249aca..acd435f5d25d 100644 > --- a/drivers/staging/greybus/light.c > +++ b/drivers/staging/greybus/light.c > @@ -95,15 +95,15 @@ static struct led_classdev *get_channel_cdev(struct gb_channel *channel) > static struct gb_channel *get_channel_from_mode(struct gb_light *light, > u32 mode) > { > - struct gb_channel *channel = NULL; > + struct gb_channel *channel; > int i; > > for (i = 0; i < light->channels_count; i++) { > channel = &light->channels[i]; > if (channel && channel->mode == mode) > - break; > + return channel; > } > - return channel; > + return NULL; > } > > static int __gb_lights_flash_intensity_set(struct gb_channel *channel, > _______________________________________________ > greybus-dev mailing list -- greybus-dev@lists.linaro.org > To unsubscribe send an email to greybus-dev-leave@lists.linaro.org