Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4667084rwl; Tue, 28 Mar 2023 09:38:31 -0700 (PDT) X-Google-Smtp-Source: AKy350aw9ezU6NUILDecaLlPphk2zV7K8cFdA8UDSfzfVFRwLoSw8ppMmvxxv/L2OFIFVhfgkeUj X-Received: by 2002:a17:90a:bc85:b0:23b:2f4a:57bb with SMTP id x5-20020a17090abc8500b0023b2f4a57bbmr17816617pjr.10.1680021511112; Tue, 28 Mar 2023 09:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680021511; cv=none; d=google.com; s=arc-20160816; b=LKSKiCxsYpiiS+KCZq88izk/voudYEvSgnumglN17fPfTcx3adIpPQTAeoUi7SFyZf gZs6Apj35L5Zwhy7mJmpEAj8W2D67kesjMbMtGjhpgxfgjmidwM6rAWRyfxUZIDV+AgU gOFtmJAGjNo+RC3FhCetD+TjgQjbDT8/Yc1BvfWvqDZG8YOv6aXdFrHj7QTYWi+NmI4D 0zZ2zNEBCDNIfbV9CN5EGGxJFwS5KbFRvI7r2oRcyYohQvZ+QaWRm1GL/Qt/+THXUKP2 ZbPs//k7Kd0MU2h/YltgdzR3aQMl+5MTG8RLGrp4VQkWz7kN10nigIISFYKSM4UkoaNE Z1GA== 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=k+id1ddpopq8eTJxLphUTWsaPEQ5G4KemEgbZ4Fa3ss=; b=Sb6+QD3NEXC8hjiwB867zzbPE1KZu6CYF7gdS4cU1/ff7zH70MrquNAn4IaGAu5un+ 7ASuM9bRIBy1PahPQXhdRvPrN61TNSHM7E06PXaxO24Zx0YdxPr75iQ2sFSVPcLF6T/4 Nj6zSs/wApeKnphvO00HnNzEymaN6r2D1o9HkkonI+62UReAOSnRett85lR3fHs63qGh aGsPTqvyFgKGw79FvIF8moeGYi8ReVUpStASJ29PKulddSBw2b509+cSIvMOr9oVqN1J XmMAxtU/XMCApt7am1alWTuiKzdlX+IiXL3lQwW2uK9XUUWeTmtZWNUd8/uHixwyImOD /0hg== 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 g20-20020a63f414000000b0050bf7310b05si29956081pgi.690.2023.03.28.09.38.17; Tue, 28 Mar 2023 09:38:31 -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 S230095AbjC1Qex (ORCPT + 99 others); Tue, 28 Mar 2023 12:34:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbjC1Qeo (ORCPT ); Tue, 28 Mar 2023 12:34:44 -0400 Received: from 9.mo562.mail-out.ovh.net (9.mo562.mail-out.ovh.net [46.105.72.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C643EA5F5 for ; Tue, 28 Mar 2023 09:34:42 -0700 (PDT) Received: from director4.derp.mail-out.ovh.net (director4.derp.mail-out.ovh.net [79.137.60.37]) by mo562.mail-out.ovh.net (Postfix) with ESMTPS id 955F523DE3; Tue, 28 Mar 2023 16:15:55 +0000 (UTC) Received: from director4.derp.mail-out.ovh.net (director4.derp.mail-out.ovh.net. [127.0.0.1]) by director4.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for ; Tue, 28 Mar 2023 16:15:55 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.108.20.117]) by director4.derp.mail-out.ovh.net (Postfix) with ESMTPS id 7A8461FE15; Tue, 28 Mar 2023 16:15:55 +0000 (UTC) Received: from localhost.localdomain (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.23; Tue, 28 Mar 2023 18:15:54 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , , , , , Jean-Jacques Hiblot Subject: [PATCH v8 3/6] leds: provide devm_of_led_get_optional() Date: Tue, 28 Mar 2023 18:15:38 +0200 Message-ID: <20230328161541.599463-4-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230328161541.599463-1-jjhiblot@traphandler.com> References: <20230328161541.599463-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: DAG8EX1.emp2.local (172.16.2.81) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 1349672513875425755 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehgedgleekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgtghisehtkeertdertddtnecuhfhrohhmpeflvggrnhdqlfgrtghquhgvshcujfhisghlohhtuceojhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeduteevleevvefggfdvueffffejhfehheeuiedtgedtjeeghfehueduudegfeefueenucfkpheptddrtddrtddrtddpkeekrdduiedurddvhedrvdeffeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepughirhgvtghtohhrgedruggvrhhprdhmrghilhdqohhuthdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepjhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqlhgvughssehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehiedv X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE 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 This version of devm_of_led_get() doesn't fail if a LED is not found. Instead it returns a NULL pointer. 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 2c0d979d0c8a..9cddcd908bce 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -295,6 +295,31 @@ struct led_classdev *__must_check devm_of_led_get(struct device *dev, } EXPORT_SYMBOL_GPL(devm_of_led_get); +/** + * 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 ba4861ec73d3..41df18f42d00 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -215,6 +215,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.25.1