From patchwork Fri Mar 28 15:28:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacek Anaszewski X-Patchwork-Id: 3904311 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9A19BBF540 for ; Fri, 28 Mar 2014 15:29:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B5487202FF for ; Fri, 28 Mar 2014 15:29:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B6C83202FE for ; Fri, 28 Mar 2014 15:29:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752111AbaC1P3h (ORCPT ); Fri, 28 Mar 2014 11:29:37 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:40155 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751071AbaC1P32 (ORCPT ); Fri, 28 Mar 2014 11:29:28 -0400 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N3500JW2KD4V960@mailout1.samsung.com>; Sat, 29 Mar 2014 00:29:28 +0900 (KST) X-AuditID: cbfee61b-b7f456d000006dfd-b7-53359558d927 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 39.84.28157.85595335; Sat, 29 Mar 2014 00:29:28 +0900 (KST) Received: from AMDC2362.digital.local ([106.116.147.229]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N35007VKKCK6J30@mmp2.samsung.com>; Sat, 29 Mar 2014 00:29:27 +0900 (KST) From: Jacek Anaszewski To: linux-media@vger.kernel.org, linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: s.nawrocki@samsung.com, a.hajda@samsung.com, kyungmin.park@samsung.com, Jacek Anaszewski , Bryan Wu , Richard Purdie Subject: [PATCH/RFC v2 2/8] leds: Improve and export led_update_brightness function Date: Fri, 28 Mar 2014 16:28:59 +0100 Message-id: <1396020545-15727-3-git-send-email-j.anaszewski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1396020545-15727-1-git-send-email-j.anaszewski@samsung.com> References: <1396020545-15727-1-git-send-email-j.anaszewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHLMWRmVeSWpSXmKPExsVy+t9jQd2IqabBBpsvslvcWneO1eLozolM FvOPAFm9V58zWpxtesNucXnXHDaLrW/WMVr0bNjKarF711NWi8Nv2lkduDx2zrrL7rFn/g9W j74tqxg9Pm+SC2CJ4rJJSc3JLEst0rdL4Mro7djGUtAlWjH97x62BsZLgl2MnBwSAiYSE36/ YoKwxSQu3FvP1sXIxSEkMJ1R4uXhJUwQTieTxNVvS1hBqtgEDCV+vngN1iEiUC4xbeojsCJm gX2MEpumHWcGSQgLhEpcPTYBrIhFQFXi7vQTjCA2r4CHxPujnUCDOIDWKUjMmWQDEuYU8JS4 /aIdrEQIqOTLnJPsExh5FzAyrGIUTS1ILihOSs810itOzC0uzUvXS87P3cQIDrVn0jsYVzVY HGIU4GBU4uEVaDUNFmJNLCuuzD3EKMHBrCTCmzURKMSbklhZlVqUH19UmpNafIhRmoNFSZz3 YKt1oJBAemJJanZqakFqEUyWiYNTqoHRu/Vlz6zXttMXVyf9Xrx0k5fadudwy+tLL/BPl86Z n2hZ9oCfxbJvrsmaCdnVm+3aJtyc2HNCb+nuqsPCCxVSmnZf6i7KdVWV9p//mevd4cffHrmV L7X4vvKXVbJBb5SYwb0SrejLMdOWNgTxXlsmea3wr96W1WtvlQR+FEt9rCR0QUzj2vReJZbi jERDLeai4kQArtxF7DECAAA= Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP led_update_brightness helper function used to be exploited only locally in the led-class.c module, where its result was being passed to the brightness_show sysfs callback. With the introduction of v4l2-flash subdevice the same functionality became required for reading current brightness from a LED device. This patch adds checking brightness_get callback error code and adds the function to the LED subsystem public API. Signed-off-by: Jacek Anaszewski Acked-by: Kyungmin Park Cc: Bryan Wu Cc: Richard Purdie --- drivers/leds/led-class.c | 6 ------ drivers/leds/led-core.c | 17 +++++++++++++++++ include/linux/leds.h | 10 ++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 5bac140..efe6812 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -25,12 +25,6 @@ static struct class *leds_class; -static void led_update_brightness(struct led_classdev *led_cdev) -{ - if (led_cdev->brightness_get) - led_cdev->brightness = led_cdev->brightness_get(led_cdev); -} - static ssize_t brightness_show(struct device *dev, struct device_attribute *attr, char *buf) { diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index 71b40d3..41f2a6a 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -126,3 +126,20 @@ void led_set_brightness(struct led_classdev *led_cdev, __led_set_brightness(led_cdev, brightness); } EXPORT_SYMBOL(led_set_brightness); + +int led_update_brightness(struct led_classdev *led_cdev) +{ + int ret; + + if (led_cdev->brightness_get == NULL) + return -EINVAL; + + ret = led_cdev->brightness_get(led_cdev); + if (ret >= 0) { + led_cdev->brightness = ret; + return 0; + } + + return ret; +} +EXPORT_SYMBOL(led_update_brightness); diff --git a/include/linux/leds.h b/include/linux/leds.h index 596555a..c02dd7b 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -148,6 +148,16 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev, */ extern void led_set_brightness(struct led_classdev *led_cdev, enum led_brightness brightness); +/** + * led_update_brightness - update LED brightness + * @led_cdev: the LED to query + * + * Get an LED's current brightness and update led_cdev->brightness + * member with the obtained value. + * + * Returns: 0 on success or negative error value on failure + */ +extern int led_update_brightness(struct led_classdev *led_cdev); /** * led_sysfs_is_locked