Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1086648rwb; Fri, 7 Oct 2022 08:00:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7fXMBbm6wZiFxMGq9ES7tD1RVu4WGSSH6t5JT3/bHzW12gxCGhYWmY2K4/9IHhNvkkzs68 X-Received: by 2002:a17:907:744:b0:741:36b9:d2cc with SMTP id xc4-20020a170907074400b0074136b9d2ccmr4294062ejb.613.1665154821606; Fri, 07 Oct 2022 08:00:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665154821; cv=none; d=google.com; s=arc-20160816; b=MWYqzNkJcip1O1fm3FYQPCIVDr+9U6b+r2C3oor9U3et7E9rn0O976P5JFnVCnVbWp u6xhsuDHX//vqylQzrg3fHT95dP32TY7hTFEPpuvPnHgOg9vP6eXLQXmKAcqjGLgl26u Ams8cQnQpBzySGCjsu5T9ceznuKP5pcA4nTfU2hsFNgMhyEGPJde+mnmpBXNMKDE9UO6 i+vcS31GYef53NpWlykZIifSU4RQBgVMkNfQF2LMAWjDMa5tGh6D+8gUggZYMyBeB0Wy muqB/vilLl1m2KwLSOzoZhRlzn2qxIuqREoDm6C28P79LaGTZWXK0Z74F1MDqqIUaGb7 usBg== 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=W8//QzkKztcY3ENH0MbWkDDGTQi+zOm5AsIcKCLAFkQ=; b=RXtd0qQp/7yKdwqlwU37GJ+xdvkLZsc+HzUBQsZPXegaQ4QgLn9UkG2Oq6ITZwk4UY Xsrj6XUB3Z2SzYMoFz9/XbJBD0ofW97ixwmDEQ9Mkd6sNGC2oy5L4hCkAAhJQND8DKyp F/UMkARsf3WTaiMuYoULxmHU243/wOWWSAiFvrH3dxcAJ7bicliCf7E+dLCCTmWowChJ NHh+oUXtPBIfwJxrkFjVrh5ce0tBZuJR4qO3JDcpg0i4NDks/Tqt/Zb1QHE/BQgBmK/9 inLZA0kKw16bDkmk2Kj/xGZ3n2NF09PX/GoGhPTe0g74UVvv5hXwGV5+SVibHe7+fw/T nuNw== 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 j14-20020a05640211ce00b00458f9a933c2si3025316edw.67.2022.10.07.07.59.41; Fri, 07 Oct 2022 08:00:21 -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 S229927AbiJGO5A (ORCPT + 99 others); Fri, 7 Oct 2022 10:57:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbiJGO4y (ORCPT ); Fri, 7 Oct 2022 10:56:54 -0400 Received: from smtpout1.mo528.mail-out.ovh.net (smtpout1.mo528.mail-out.ovh.net [46.105.34.251]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80EBCB03FA; Fri, 7 Oct 2022 07:56:52 -0700 (PDT) Received: from pro2.mail.ovh.net (unknown [10.109.146.13]) by mo528.mail-out.ovh.net (Postfix) with ESMTPS id 009C512E155C3; Fri, 7 Oct 2022 16:56:50 +0200 (CEST) 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.12; Fri, 7 Oct 2022 16:56:50 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , , , , , , Jean-Jacques Hiblot Subject: [PATCH v4 3/6] leds: provide devm_of_led_get_optional() Date: Fri, 7 Oct 2022 16:56:38 +0200 Message-ID: <20221007145641.3307075-4-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221007145641.3307075-1-jjhiblot@traphandler.com> References: <20221007145641.3307075-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: CAS1.emp2.local (172.16.1.1) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 4481926058042800603 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeijedgkeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgtghisehtkeertdertddtnecuhfhrohhmpeflvggrnhdqlfgrtghquhgvshcujfhisghlohhtuceojhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeduteevleevvefggfdvueffffejhfehheeuiedtgedtjeeghfehueduudegfeefueenucfkpheptddrtddrtddrtddpkeekrdduiedurddvhedrvdeffeenucevlhhushhtvghrufhiiigvpeegnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepphhrohdvrdhmrghilhdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepjhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehvdek X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 --- 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..2fea79a2300d 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 parse to find the request 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