Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1670273lqg; Sun, 3 Mar 2024 23:05:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXz03BcHFWmcI4qe3HuxySoQPCiAO269++iJ0K4Zhk7UoLcGKQVRFNmmQLRGvHCx1DIYfJKOBfBJ77v2IO5oMIRVOpPSNQvSxUzfOo51Q== X-Google-Smtp-Source: AGHT+IHOubsI8D0CNyqvBc5JVEfS7XtsFeUN++ytwmVCnB9D+7BHP1gqR4ItHD5uLMvznTYLznIq X-Received: by 2002:a0c:fba5:0:b0:690:6ca4:f231 with SMTP id m5-20020a0cfba5000000b006906ca4f231mr3611886qvp.30.1709535902965; Sun, 03 Mar 2024 23:05:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709535902; cv=pass; d=google.com; s=arc-20160816; b=HiNo8vUeuxXfVtqLJc9iilHGWPhOmwpf0fAF7flhvtt61c/N+c7ZBnwrqtKNiWpUIy fI95ucv5OnSgZd2BjDdQjXufwiu1HR/mcG8GAjqQFFrLOzT1WY2U1L5cCoU5AH2CIwTE mXKhBj3QDI5CSlRHARU25DdPHV3j2LEWdiD8mykw1u+YeuLe9icn9oNSIoY7IxshCRVj tYO5z3jXvCXKkMwKIUagRvFjrKw4CbreUfxIC8aNrnz0fs6RL3YcYMTuwLwWILApFlkN ud4ISdBq8KNRrLqyx/WWsOer2ZcDbboy70ldwYDW1ncTgXkO94GUrIwibtht6ii3379c K6RQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=/RTu2QOOVQbOweB1LGR/BRbdQUT3nXvJVjgo89rA8a4=; fh=wWjyM/7PyhZlkxL1oV52Nv5jBpR8OHY/gHmo6lBEJHs=; b=odTPBssvNQXxOg3OQ/5Lcq7baQG+C4t4T7NcfzGB6Tznxcy8m+c9A7vuGYxTxv8cOj SZVTytpmEgMrM8JHcVE+qp+1Tmqi/dplGx2YsbsQVdTXPkML5JPQ+yX7SoCJwCjbJigv G82GSobai280ka/nvUrbILv+Hn6kOOJMNI3yQmQJJnPVAQ2vfX4N2zcxeKyNSfoRR8Cc mTlHRy5Pf3aZx9jUpFHDCaNq36DmICMUDzWGrxPZRj8bgyddVebP9nLKRENGdl8V256Y uvuN+vmhKIeo2wRvkrMOi63Eml5rKgjbOW9eMJ+caCGyL6hxRSR3xgLW4kpYZdaNhBMh NFLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QqgxkHIn; 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-90105-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90105-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j9-20020a05621419c900b0068fdd6d16easi9360820qvc.554.2024.03.03.23.05.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 23:05:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90105-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QqgxkHIn; 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-90105-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90105-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B10701C210B9 for ; Mon, 4 Mar 2024 07:05:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E97D5134B4; Mon, 4 Mar 2024 07:04:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="QqgxkHIn" Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 EBFBD1170A for ; Mon, 4 Mar 2024 07:04:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709535895; cv=none; b=Pcde8Cbl60Tym18AlUIEdefeeIdWpA4XpBF965MKGG6SroviixH4AZmkLk1D1DSwG+HM2Gk5bGKOm99fQW8E27Q3LXx2octf1v1XPKFidyDJYqQJV/AVKNEgwdaJVtO7m6Zo+4+aa6yYOKka5tMYaUdSISQmvCtpq+IeH2pQoLs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709535895; c=relaxed/simple; bh=fOzF9T+7+v6nbIr6JpI2D3fB/kcAd613CX/CdSkUuJg=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=FOxZTBlcMwNbUOsir4aVld+uobiOUQ0DuwoBwGoQ5FfVwUla11CfOXvwA9LpUhNVqF9Q3cWLB/VGmYTSkmCavIpdiJQNSUWukfy8jhLgcoB/dluzK2Z9gVNXhxglNO7xSEhOataSMh/awtIIMfjP74HcfyZSnBjQ64NZYeIRFrA= 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=QqgxkHIn; arc=none smtp.client-ip=209.85.128.53 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-f53.google.com with SMTP id 5b1f17b1804b1-412e22315d8so4889235e9.1 for ; Sun, 03 Mar 2024 23:04:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709535891; x=1710140691; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=/RTu2QOOVQbOweB1LGR/BRbdQUT3nXvJVjgo89rA8a4=; b=QqgxkHInV4+gl4HHNp17XXNyik/Bcn8YA+vnUVHB2DLacIH2Gwt2E8Oe5Q4zouwm6+ C5WexYBrTa6PQ/E49dwt2JzHQ7n90zKCsshi0WG6JhiMtvF53EYTLYAaBK0PXlYbjrr5 haP3oJNHMlFC0HeQAVchgCmV+pTL2HAYvVCYmOAw9egIPE7bZg4yCY1hANdokMsbpZPn d9+BsM0pxdwB/Q58Fj9UT7YOUjyL1fStrbeLEpYVs64XEgGzRcmRASN+aPnzfAGBU4tg 0wr6yj6TjGQ54DWlDFcw2Dl5IOgpidxYzUPqq195CVNevcL0riPNHmF8BR+qzSLBnN6V TXHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709535891; x=1710140691; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/RTu2QOOVQbOweB1LGR/BRbdQUT3nXvJVjgo89rA8a4=; b=OXLqdUz8D+4GalbIL3slnyxyPOtnaRfrSJOX+0LeRvIadcWvIb9rS9ODWYt3vRIqJY 1DywOWMyDNSUR6FdIJWLcwOUSkW5Xnn+1G/Q5vPvB96kpBLE+YhAJx3QnK4EN6l3LNwh 5eQhzk4D6GHBkG7FFGbxRMt9aGmc3urR0JnUSHQIpaDHt3SkNMceInl3IRMsqrnVPZa5 pJQ7jbWe0+UzOo5EdvF5Rz9ZB9sVkSr4Z2QR8lC4Boa0rFJw2GePwdnSCH6m13HZPF+c 9BIof9YQk2+m/MUiVjpGV+jGeXok/3Dhm1iv9uggc2vkh1TExjNgAnDqzc+PDkRLV8Rs fu6w== X-Forwarded-Encrypted: i=1; AJvYcCW16z5ubh7UKA4iZj/KzUMb0fQtaqK6ZSl+rgo53AD8HRzI979c2GioOlWddpg0QKUmEs8XJQy9GB0liEHdqTHYYvFkgPzfvgfNigtz X-Gm-Message-State: AOJu0YxCeLTrEAWKTtvMaw7iuq7yoCDTB0myBaeB6YZP8axFbW17vWhb 1OHhuNA0cF0gJaTCLunFbHMj47wrfVZIg33SUBJIS9FTnVhWI4KDWKn9ln3ejoE= X-Received: by 2002:adf:9c8b:0:b0:33d:47d6:c159 with SMTP id d11-20020adf9c8b000000b0033d47d6c159mr5733432wre.12.1709535891433; Sun, 03 Mar 2024 23:04:51 -0800 (PST) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id r18-20020adfca92000000b0033dcc0d1399sm11375456wrh.25.2024.03.03.23.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 23:04:51 -0800 (PST) Date: Mon, 4 Mar 2024 10:04:48 +0300 From: Dan Carpenter To: Rui Miguel Silva Cc: Johan Hovold , Alex Elder , Greg Kroah-Hartman , greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] staging: greybus: fix get_channel_from_mode() failure path Message-ID: <379c0cb4-39e0-4293-8a18-c7b1298e5420@moroto.mountain> 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 X-Mailer: git-send-email haha only kidding The get_channel_from_mode() function is supposed to return the channel which matches the mode. But it has a bug where if it doesn't find a matching channel then it returns the last channel. It should return NULL instead. Also remove an unnecessary NULL check on "channel". Fixes: 2870b52bae4c ("greybus: lights: add lights implementation") Signed-off-by: Dan Carpenter --- drivers/staging/greybus/light.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c index d62f97249aca..a5c2fe963866 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; + if (channel->mode == mode) + return channel; } - return channel; + return NULL; } static int __gb_lights_flash_intensity_set(struct gb_channel *channel, -- 2.43.0