Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2604708rdg; Mon, 16 Oct 2023 09:10:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFg5FFkuSaiq3zV4kDNtt3EDtVQM6tUBaouJfDw4xOK7fqmO7+5P58aBbQ4bhQ25YZRQ1XK X-Received: by 2002:a17:902:b7c9:b0:1c9:d908:d60c with SMTP id v9-20020a170902b7c900b001c9d908d60cmr10353882plz.63.1697472631554; Mon, 16 Oct 2023 09:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697472631; cv=none; d=google.com; s=arc-20160816; b=kdMqbVphyzqb2M+MCzpeOqL8qMVETmEA5WvU7NfrtZ75HPH+OTPIHDB5SWyThpX/gm 8rxBLTPWF8F18Xa6+9+4EGN5F1RcmWXEOyo3u4Qb8R4CAGvRohM6Qm18UIN0ToKzc2TM p33blV/RiMf1H8P9gQaWJU8PAKjtqXYkwmBdBKSUsI3OVrC+im40bcLUofxoOKCJscn7 BpCR+/q7TC8MQswGfyLyjyHNdo8BqCZmTkVlUp8z+TastMbHDY6Ip0yzD/rYiprlQvMi nIBPmh827TIe/y6AneqGB2Yug2bV+YVvWQgRNcfZAHW7K8u2FKM9xWycylPkqAmnijKQ SYgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CDR1a7xt6ZJYPRWWiq0CblEP4joA3afoPGYLYgeKJis=; fh=tUAC4oQq3UuKajr6ZMoB53sspoioCuMU4y0NrDbDhac=; b=WOMUnMCisp0v9ud0ja6dot4ZA5n+8bpq4Phun8uRfhqCoCXwWqqa429T2MUjH7cwmu eljirofdW94ghSPtDblXpDYiJ9rQEOjpNlgbApi0gF3rTDSJ8AQnryyno808Pc026+Gg vSOT0qmHmCXE8/zlT70JTqZwFoHzpD6Q/tsAMetpSX9EWp7E4te8bxf6KBFLb50XHKOw nI56zakbCZYPFpyDJxzsxCtjm67BxqlwRFyw5X2o2qbc4J5Up9LChvgJ8NZkLWMiYtsw ad4LpspEIw3fJYbDBvzAKNuB/x6NT0KKFD3p+ht1Cjsip4fK5FntGWjKUoiXUe0a11hR OJ8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W3XBeBwP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id s3-20020a170902ea0300b001c62ce41077si12039525plg.492.2023.10.16.09.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:10:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W3XBeBwP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 475CE8041C1D; Mon, 16 Oct 2023 09:10:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233266AbjJPQKS (ORCPT + 99 others); Mon, 16 Oct 2023 12:10:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjJPQKQ (ORCPT ); Mon, 16 Oct 2023 12:10:16 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7482AE6; Mon, 16 Oct 2023 09:10:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697472613; x=1729008613; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r8k8DrgrN+0Ylm+kKwsZKCjBoAC5iHc0h68Upva4lbg=; b=W3XBeBwP0RCbyD6FFJ4ceCkk822Bpj/04V+aN8hVF/zFR15tlSy5va8j Mm/SGAmt6uMwlOZWm9ROhZ7kmwjp7hQEp4ks6RnzS1EsIRQUKmCWEG80v nDrCG6t2w2qDXrjJvKQ6Mq7B9EE9FC9ZLFqsKZSAZcMQqTlNTAJjmVssc ffL3WMxdibM+w+pvIOnDFiAepyghe4R171MYYrAbwugZxiA1tl1BskwK6 iA+NnfrgGu976NKCUJbecXFsw0/+GMsrySpTQXKcz9L9HM0gjJszxMNua yLU9yZkPu1b/c9Zy0ZCz5d/AEaI8CQ4klq1WeanQIwKWgmUa8ZrgFpX59 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="4175724" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="4175724" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:10:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="1087124867" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="1087124867" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 16 Oct 2023 09:10:09 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 164EF85E; Mon, 16 Oct 2023 19:10:09 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Pavel Machek , Lee Jones Subject: [PATCH v1 3/6] leds: gpio: Refactor code to use devm_gpiod_get_index_optional() Date: Mon, 16 Oct 2023 19:10:02 +0300 Message-Id: <20231016161005.1471768-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20231016161005.1471768-1-andriy.shevchenko@linux.intel.com> References: <20231016161005.1471768-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:10:29 -0700 (PDT) Instead of checking for the specific error codes, replace devm_gpiod_get_index() with devm_gpiod_get_index_optional(). In this case we just return all errors to the caller and simply check for NULL in case if legacy GPIO is being used. As the result the code is easier to read and maintain. Signed-off-by: Andy Shevchenko --- drivers/leds/leds-gpio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 4071cb9eefec..7c9c6a93dfd7 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -218,13 +218,13 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, * device, this will hit the board file, if any and get * the GPIO from there. */ - gpiod = devm_gpiod_get_index(dev, NULL, idx, GPIOD_OUT_LOW); - if (!IS_ERR(gpiod)) { + gpiod = devm_gpiod_get_index_optional(dev, NULL, idx, GPIOD_OUT_LOW); + if (IS_ERR(gpiod)) + return gpiod; + if (gpiod) { gpiod_set_consumer_name(gpiod, template->name); return gpiod; } - if (PTR_ERR(gpiod) != -ENOENT) - return gpiod; /* * This is the legacy code path for platform code that -- 2.40.0.1.gaa8946217a0b