Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp796936lqg; Sat, 2 Mar 2024 02:06:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUvWbqGLwcn2G8+bOg14HCXV928p6N3PLqo7L9RAJVmQK4RNOknDlygG0PmOasapRxfTLS4Voa/Lzb3uyYuk6iDPuRcC9Fpii1JplVFOA== X-Google-Smtp-Source: AGHT+IHuKgSZDu3kAxJhRfZxfqsszk2fw/WZUnEx9yA4FvPjqFKr+vhhUGgtQhB/cWFyyU6Gmkr+ X-Received: by 2002:a05:6a00:2188:b0:6e4:59b7:1dd4 with SMTP id h8-20020a056a00218800b006e459b71dd4mr4456885pfi.31.1709374018978; Sat, 02 Mar 2024 02:06:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709374018; cv=pass; d=google.com; s=arc-20160816; b=F6cfw8MQemKfQHTsNaFS6tDd+Ge0HNzohVQ01qUMTVoZUDUU4TYc9fehova5Bw2qTD tHpooDWKEOwzAdEyVdAytMp/TepWVlm4CRyC+bZnBj3kbN+QmY8jyx2SoUGt3oA5BWj1 4JAViKeM8YMwZ/tFtAiwfpra73lTubPYth6Mg7ZsOKR06pnc8ZF4yr7PT2qT5h8yJfLS g0VAg7Er5FgODOqCGDC7+JUbWJmPVNosQTA/owujgVP4Co06mcwLsz8/p/fIIV3acmGq CTaaCibmHzI9zYi9exUuEn75+xwkqsjDurRCgJigzaggaGlJr4JuXEjsoDuy4wt117Ns 8onw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=WXevwhgIr2J2YRRZ5pTYABsmmlbW89cM1iNV1W0EhcQ=; fh=LuLjhOSnoZgtjTuhGFuBFEq9+dbePqvOll38cGRF2Sg=; b=IfxJdtMaXxg1QdYOf+QGDDpgL5+1w0aozDBZrkmdq9cBhSechC3jOJqfgklpCRteCP t1o8+EfvwfyQWio/FsGAJomxM1o1gHu1ROK0f0Bx71Ck5P18pidcJ9GCpTd6jUsj4ZC2 CARR1RTqCkrtI89eoUDWCU6agrBhYydc2gDK0+pA0Lox8YkPM7OsP6PvBby8Xs6qf/9m eVhMkBhuR9IfG15PpQKeQO+sRHmL4uNDWEMJhJF+6CfvY93UxtuvJ33mNMhwXHrKqp5A aVOYoN6gZiKbACjmgvdVy3npJ8iaSTs3CEsjsjF3uNZIcoQWPZtmVQfS0+wKcBjojLJw 4zow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l7Wxz9Li; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-89407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 c6-20020a6566c6000000b005c658bf30aasi5136648pgw.412.2024.03.02.02.06.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Mar 2024 02:06:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89407-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=@linaro.org header.s=google header.b=l7Wxz9Li; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-89407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 BA4B5284C7B for ; Sat, 2 Mar 2024 09:59:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D84514298; Sat, 2 Mar 2024 09:59:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="l7Wxz9Li" 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 AC00613FF1 for ; Sat, 2 Mar 2024 09:59:50 +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=1709373592; cv=none; b=J2rYqcjEhxXoadFUYxlk1x9EaIf6o1cal5nNDWVdouL98qoOuHHC8WEtXzjs33CzmE7/gwNPdbNmBia+o1JYYUrR5F7250xj++XIeTfg5A50KY8m5CK+NCvLyJQE8EhaDxJOS8Ykih9/57isOZt8JAPBwxdJqryKjAu9nQEpEls= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709373592; c=relaxed/simple; bh=/0GFsJ+1/uHwP0+rcrGwi4dtraL0RyOLUoywuy05330=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z8sSbcaqqWcwnq7H46jyLmp37JbMUfLL38ihtrWUHO/viINOj9ykSvoHatmkZUgOTZBFsAayXxP9o5Ymk5HGML9f9TjkQI9sm71rgzWozXONEBNE5dJxItjcH/wvxEs9hwnS5cW+7U9nTOcTgReOOOj3oY/LV9YlnNb3VuIPWjo= 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=l7Wxz9Li; 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 Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-412d67e4e91so1176695e9.2 for ; Sat, 02 Mar 2024 01:59:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709373589; x=1709978389; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=WXevwhgIr2J2YRRZ5pTYABsmmlbW89cM1iNV1W0EhcQ=; b=l7Wxz9LiZVMUn68zuaquq+z33QQTyD5a8apPGccQzDOSWJCiIAd00BbbppIGkrshr3 /b/vZw6vKC9yaRVnrasO/aUoSN48I0nmflv7X4O7JDZ2YXKvl4fEmtNk0O/6E/K1EvXh io34SLGAIJkxA83GPhbgAVVuvYdb4CgRo5pllm29PyHWm567j0flAddfSktok0VxS6lP 5qU+3gzRg6s+SML8fPZ55iAOpOvBRj2zKxCTUIg4VaLyTmBNfpsd4/0k1RZI+P7OX/pI KrvqNwQDYsfbzDuXgfgnjUBUWN+h2dQfDSEumsLkol1YRTs3rvXO1rlYqb2c/Yvhz9OU l0iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709373589; x=1709978389; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WXevwhgIr2J2YRRZ5pTYABsmmlbW89cM1iNV1W0EhcQ=; b=KAzcUbyLkjCuOwFfsJdnsUe+ZkeJAiovYh3fs+fzbGwHQi0HJVFwHRTL8xIsbl5nY/ JAMlQO40lIVOjI/1GyRSIFYNQs/3XJ+aGoMkL3hhIzpKXlCstqzPOacfVgHAZISiJATV 4INItlrsWw8FoqPJwwl4FlkwF1sURqjfE45GLcM3UCSXmeEPowjEowCaS5VvyZB6+LdU IOJA4uXP5xZ2vAzvJXIt0UB/qhbpogElV5CPRhp7V/QH6xSexV6KZwOJOCa5hC2yGT40 GsKlhAKltet4FQshT9DH1SQVps7aCkPR4UAGapaEgGhf6dt1zTFG4qczwkD+e68h+RaF shIw== X-Forwarded-Encrypted: i=1; AJvYcCUc5K0bVDa6jbr5kXJm2rF/Y8pXhIxj+Dgl+IhHSO42gUigLWn3cSfRbERnbcHUB6teiJqeZt8TC3Zwtodl+yqz91fS/TKGSoKWLL0g X-Gm-Message-State: AOJu0YxoA1ZCdOSdjiuziNK0TIfKVgMhdaff1sy+wAdPqgbRZr06n3QJ hc3Tm17XOxvj4OaOspbn2dwnZJ/PHDb8UwTVRrmN5OSMmxvtQGVZnhqdhKjY21o= X-Received: by 2002:a05:600c:5192:b0:412:afed:5cfb with SMTP id fa18-20020a05600c519200b00412afed5cfbmr3731099wmb.15.1709373589034; Sat, 02 Mar 2024 01:59:49 -0800 (PST) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id z9-20020a05600c114900b00410bca333b7sm10876433wmz.27.2024.03.02.01.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Mar 2024 01:59:48 -0800 (PST) Date: Sat, 2 Mar 2024 12:59:39 +0300 From: Dan Carpenter To: Mikhail Lobanov Cc: Rui Miguel Silva , Greg Kroah-Hartman , greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] greybus: Fix deref of NULL in __gb_lights_flash_brightness_set Message-ID: <7ef732ad-a50f-4cf5-8322-376f42eb051b@moroto.mountain> References: <20240301190425.120605-1-m.lobanov@rosalinux.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240301190425.120605-1-m.lobanov@rosalinux.ru> 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. 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,