Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2401410rwd; Fri, 16 Jun 2023 03:24:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ztRg1cwd9gZJlVJJl2m5ksItcvF2pRZYUc80w6K7Yj1yDAOPRPwNDs9yhCGD0UGrjKCga X-Received: by 2002:a05:6358:c321:b0:129:cec7:bb11 with SMTP id fk33-20020a056358c32100b00129cec7bb11mr1024939rwb.31.1686911057824; Fri, 16 Jun 2023 03:24:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686911057; cv=none; d=google.com; s=arc-20160816; b=M6nQIys8Rd7nfwmD2FaancatEtsYpLvyvJnvx0mHmLyf3sPifPtYNEp8nFEQwqkyYL 8OPpwksuXXyRl5x7GnFWXw/UAEAinSEcoYaCWv6SOZX4ZcPgCIgXV7Y73JzJf4igYTAb fyQ/9POgG3BafaimOYFLXjl8rFeiFAj8oGtB9lzEmbadHVYFydXKxPf8URT8YwkpwS8a +F9nigDuzy1Mwa+6ngbwPurIBEHnTM23tFyGvS647Wezo1uD2CgAX2tDYkrzt3HSyvji HkSRRPA8/gK+lNvE9ibgpWWIfurMcw106tG7IfW3C9o193lEPxfENmuIaiWR7XJHT4FT qmjQ== 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=zXd8zKw3zYhJaKrPqJZydrWWFB6X+Pv4tOTAma0ECTo=; b=hXHZfopDzWZO4F2+zC2M8ByhH+e/oEhkZUmzKeM2mjfeC8HsgbA0ti0HqbbUsUNy74 05Tke4YFRLc/gLMr1V+Lud8lsneMGkVOvjL/pfiEfk1pnzQ0XBfI4Okr3JA528aU7dGk FsnLJpWBqxXudAP5ZlMMKjGBxg2l7muQ0E0eQWbCpqkL0AaLyU/3zoHmOEPhlvt97zNo EaQIwoTOZmSGiSeoRi2PRXokHsUCGXN9Rg9UUa17FyQmdekwrLVUT9j5OhwJR6uCBcIp AGFI6Govkzo1VSf6zgTbCpUxnXZi1PzQQUPU1/GEqdeQqDFN1Gp+zNsqfs1HTOrKVg8h R/RA== 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 g2-20020a63ad02000000b0054fb1d593bdsi7365772pgf.749.2023.06.16.03.24.02; Fri, 16 Jun 2023 03:24:17 -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 S234512AbjFPKQh (ORCPT + 99 others); Fri, 16 Jun 2023 06:16:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244477AbjFPKQa (ORCPT ); Fri, 16 Jun 2023 06:16:30 -0400 X-Greylist: delayed 613 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 16 Jun 2023 03:16:28 PDT Received: from 5.mo562.mail-out.ovh.net (5.mo562.mail-out.ovh.net [46.105.48.192]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8BEAAC for ; Fri, 16 Jun 2023 03:16:28 -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 847CF23F68; Fri, 16 Jun 2023 09:57: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 ; Fri, 16 Jun 2023 09:57:55 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.109.138.83]) by director4.derp.mail-out.ovh.net (Postfix) with ESMTPS id 4A9DD1FE53; Fri, 16 Jun 2023 09:57:55 +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, 16 Jun 2023 11:57:54 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , Jean-Jacques Hiblot , Andy Shevchenko Subject: [PATCH v9 2/5] leds: provide devm_of_led_get_optional() Date: Fri, 16 Jun 2023 11:57:43 +0200 Message-ID: <20230616095746.872220-3-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230616095746.872220-1-jjhiblot@traphandler.com> References: <20230616095746.872220-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: CAS3.emp2.local (172.16.1.3) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 3612731328970570119 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrgedvgedgvddvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfgtihesthekredtredttdenucfhrhhomheplfgvrghnqdflrggtqhhuvghsucfjihgslhhothcuoehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepudetveelveevgffgvdeuffffjefhheehueeitdegtdejgefhheeuuddugeeffeeunecukfhppedtrddtrddtrddtpdekkedrudeiuddrvdehrddvfeefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpohhuthdphhgvlhhopeguihhrvggtthhorhegrdguvghrphdrmhgrihhlqdhouhhtrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomhdpnhgspghrtghpthhtohepuddprhgtphhtthhopehlihhnuhigqdhlvggushesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheeivd 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=ham 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 6dae56b914fe..eb1a8494dc5b 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 50b2f8f153fb..95311c70d95c 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -270,6 +270,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