Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1455585rwb; Fri, 28 Jul 2023 09:36:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlEtqhIQMxM+JlAYtFy0cTOdmkB1/15aRwQux3HFoj2Df8/q+EAO9gKngIzVOWpgirNTZerT X-Received: by 2002:aa7:d9d9:0:b0:51d:f5bd:5a88 with SMTP id v25-20020aa7d9d9000000b0051df5bd5a88mr2062169eds.38.1690562167131; Fri, 28 Jul 2023 09:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690562167; cv=none; d=google.com; s=arc-20160816; b=gTcGdmbqnVctdSi9jyiiyeBWsi3I7XJN7Anl4NRKX4aY6pgnBhIZIO5Q3P1/7BMvvE OagH0JHcPGcVGHjgDFiMMQDttAWIj4hfka+YxEwGF2IEo3PDibnvAFMGWIjzdIQZi+Dv Udx1CDCszVDoIXcLHwOO7e9xAhMODZMf8s8vtHpnSgEpK8AFCEVI8aYwGolekhfFFWiI u45zsoVn3lrrOCHQ34hSePpMrH95WupCSIxQZ7bmjjL1nBpNomskHXJrwe5v+7pz6AiD 5ikvpqNGjasAFNOjfQq09YtiTc0XVafXl7aUgse7LPvjKNkYz09LoDE6fJeJtAlLkJi9 +6mA== 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; bh=oITxVBzs4/bivdJ4fpVUBfJzJEaLX4XOVWEoPdU2pgo=; fh=EGRoNRtgaiBqdPqwJCj3M9D7jnCUDmzfReXXTqOmf+A=; b=ot9+d41MbGfEZS9kLwDs92SqAI4TiSr039dW1RUysddDG76vad8VZEDgcIyLoF5nTV v05tHqF6aAYeBM+++dSstRCJhcLh5jhZhxUDIUTkTxrKuT+eoxc+0q67BcCdNDmcT5uh 2CY9TTtVfwgA0F0+dvclfgh63rvpk8shNgMXcjM8StGfo8r1k6BSBEI/ZmHizY/tmKIX sOerA1EtmVUjGHYO/QMT9/FeD47qiYtHLc5lQGziAx0loQJsnfjf14o7mkpOXSliHa3B eNNybq7l4Lore6tQTGC6FZ2rn7pdnskdIW0YdOWem16cpO8wIE2G8/DbJz37VAlYjINW DTxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020a05640206c400b0051dd43b81b0si2748392edy.25.2023.07.28.09.35.41; Fri, 28 Jul 2023 09:36:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232814AbjG1QQJ (ORCPT + 99 others); Fri, 28 Jul 2023 12:16:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231202AbjG1QQH (ORCPT ); Fri, 28 Jul 2023 12:16:07 -0400 Received: from 1.mo563.mail-out.ovh.net (1.mo563.mail-out.ovh.net [178.33.106.244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0DA93AB4 for ; Fri, 28 Jul 2023 09:15:59 -0700 (PDT) Received: from director1.derp.mail-out.ovh.net (director1.derp.mail-out.ovh.net [51.68.80.175]) by mo563.mail-out.ovh.net (Postfix) with ESMTPS id 58EA4229C0; Fri, 28 Jul 2023 15:37:43 +0000 (UTC) Received: from director1.derp.mail-out.ovh.net (director1.derp.mail-out.ovh.net. [127.0.0.1]) by director1.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for ; Fri, 28 Jul 2023 15:37:43 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.109.138.11]) by director1.derp.mail-out.ovh.net (Postfix) with ESMTPS id ED9EB2011DD; Fri, 28 Jul 2023 15:37:42 +0000 (UTC) Received: from traphandler.com (88.161.25.233) by DAG1EX1.emp2.local (172.16.2.1) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 17:37:42 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , Jean-Jacques Hiblot , Andy Shevchenko Subject: [RESEND] [PATCH v11 1/4] leds: provide devm_of_led_get_optional() Date: Fri, 28 Jul 2023 17:37:28 +0200 Message-ID: <20230728153731.3742339-2-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728153731.3742339-1-jjhiblot@traphandler.com> References: <20230728153731.3742339-1-jjhiblot@traphandler.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [88.161.25.233] X-ClientProxiedBy: CAS4.emp2.local (172.16.1.4) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 16196914588195699079 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrieeigdekkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgtghisehtkeertdertddtnecuhfhrohhmpeflvggrnhdqlfgrtghquhgvshcujfhisghlohhtuceojhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeduteevleevvefggfdvueffffejhfehheeuiedtgedtjeeghfehueduudegfeefueenucfkpheptddrtddrtddrtddpkeekrdduiedurddvhedrvdeffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepughirhgvtghtohhruddruggvrhhprdhmrghilhdqohhuthdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepjhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqlhgvughssehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehieef X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add an optional variant of devm_of_led_get(). It behaves the same as devm_of_led_get() except where the LED doesn't exist. In this case, instead of returning -ENOENT, the function returns NULL. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Andy Shevchenko --- drivers/leds/led-class.c | 25 +++++++++++++++++++++++++ include/linux/leds.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 4758da2b59cf..78068b06d009 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -402,6 +402,31 @@ void led_remove_lookup(struct led_lookup_data *led_lookup) } EXPORT_SYMBOL_GPL(led_remove_lookup); +/** + * devm_of_led_get_optional - Resource-managed request of an optional LED device + * @dev: LED consumer + * @index: index of the LED to obtain in the consumer + * + * The device node of the device is parsed to find the requested LED device. + * The LED device returned from this function is automatically released + * on driver detach. + * + * @return a pointer to a LED device, ERR_PTR(errno) on failure and NULL if the + * led was not found. + */ +struct led_classdev *__must_check devm_of_led_get_optional(struct device *dev, + int index) +{ + struct led_classdev *led; + + led = devm_of_led_get(dev, index); + if (IS_ERR(led) && PTR_ERR(led) == -ENOENT) + return NULL; + + return led; +} +EXPORT_SYMBOL_GPL(devm_of_led_get_optional); + static int led_classdev_next_name(const char *init_name, char *name, size_t len) { diff --git a/include/linux/leds.h b/include/linux/leds.h index 7d428100b42b..8740b4e47f88 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -313,6 +313,8 @@ extern struct led_classdev *of_led_get(struct device_node *np, int index); extern void led_put(struct led_classdev *led_cdev); struct led_classdev *__must_check devm_of_led_get(struct device *dev, int index); +struct led_classdev *__must_check devm_of_led_get_optional(struct device *dev, + int index); /** * led_blink_set - set blinking with software fallback -- 2.34.1