From patchwork Fri Apr 11 14:56:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacek Anaszewski X-Patchwork-Id: 3969201 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 60EF3BFF02 for ; Fri, 11 Apr 2014 15:00:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 39A142077D for ; Fri, 11 Apr 2014 15:00:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B95B20776 for ; Fri, 11 Apr 2014 15:00:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932361AbaDKO7r (ORCPT ); Fri, 11 Apr 2014 10:59:47 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:43408 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754371AbaDKO5c (ORCPT ); Fri, 11 Apr 2014 10:57:32 -0400 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N3V00ILPG7V1B00@mailout3.samsung.com>; Fri, 11 Apr 2014 23:57:31 +0900 (KST) X-AuditID: cbfee61a-b7fb26d00000724f-86-534802db9012 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id DE.B9.29263.BD208435; Fri, 11 Apr 2014 23:57:31 +0900 (KST) Received: from AMDC2362.DIGITAL.local ([106.120.53.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N3V001BPG6V0730@mmp1.samsung.com>; Fri, 11 Apr 2014 23:57:31 +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 v3 2/5] leds: Improve and export led_update_brightness function Date: Fri, 11 Apr 2014 16:56:53 +0200 Message-id: <1397228216-6657-3-git-send-email-j.anaszewski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1397228216-6657-1-git-send-email-j.anaszewski@samsung.com> References: <1397228216-6657-1-git-send-email-j.anaszewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHLMWRmVeSWpSXmKPExsVy+t9jAd3bTB7BBl9bVCxurTvHanF050Qm i/lHgKzeq88ZLc42vWG3uLxrDpvF1jfrGC16Nmxltdi96ymrxeE37awOXB47Z91l99gz/wer R9+WVYwenzfJBbBEcdmkpOZklqUW6dslcGUcnb+ZteCXSMXzW0/YGhgPCHYxcnJICJhILFq3 kxXCFpO4cG89WxcjF4eQwCJGiYOrmhghnHYmidcPdzGDVLEJGEr8fPGaCcQWESiXmDb1ERNI EbPAPkaJTdOOgxUJC4RKXHn/hg3EZhFQlZg9/QM7iM0r4C6xZuJsli5GDqB1ChJzJtmAhDkF PCTuPFzDAmILAZUcez6VaQIj7wJGhlWMoqkFyQXFSem5hnrFibnFpXnpesn5uZsYwaH2TGoH 48oGi0OMAhyMSjy8GRfcgoVYE8uKK3MPMUpwMCuJ8G666h4sxJuSWFmVWpQfX1Sak1p8iFGa g0VJnPdAq3WgkEB6YklqdmpqQWoRTJaJg1OqgXHr7fQ5N5j+LwhZJOro+nWlT57r690H5Uwk 3gflLFe8fnMzR5ZRK6NdxNns1N+50oenFmxQDvg3+8ra7uPxPTLPLXyV9v0TyDpwnP/r6elO L16FMOzZpLvVJNZe4qaF0x/Wl+4ON37/rPM4uOsL251sAcHpHprFN5qW2z1Oc3q/aUdncrrN jkVKLMUZiYZazEXFiQCaIiG4MQIAAA== 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 | 16 ++++++++++++++++ include/linux/leds.h | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 58f16c3..7f285d7 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -24,12 +24,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..376166c 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -126,3 +126,19 @@ 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 = 0; + + if (led_cdev->brightness_get) { + 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 a794817..d085c21 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -174,6 +174,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