From patchwork Thu Nov 17 22:24:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 9435375 X-Patchwork-Delegate: dvhart@infradead.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 99DCD60469 for ; Thu, 17 Nov 2016 22:25:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B90329700 for ; Thu, 17 Nov 2016 22:25:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8051829704; Thu, 17 Nov 2016 22:25:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BC1729700 for ; Thu, 17 Nov 2016 22:25:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752017AbcKQWYw (ORCPT ); Thu, 17 Nov 2016 17:24:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60098 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752190AbcKQWYu (ORCPT ); Thu, 17 Nov 2016 17:24:50 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BB5F4F65C; Thu, 17 Nov 2016 22:24:50 +0000 (UTC) Received: from shalem.localdomain.com (vpn1-5-116.ams2.redhat.com [10.36.5.116]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAHMOgPW019487; Thu, 17 Nov 2016 17:24:48 -0500 From: Hans de Goede To: Darren Hart , Matthew Garrett , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Henrique de Moraes Holschuh , Richard Purdie , Jacek Anaszewski Cc: ibm-acpi-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-leds@vger.kernel.org, Hans de Goede Subject: [PATCH v5 3/6] leds: triggers: Add support for read-only triggers Date: Thu, 17 Nov 2016 23:24:38 +0100 Message-Id: <20161117222441.31464-3-hdegoede@redhat.com> In-Reply-To: <20161117222441.31464-1-hdegoede@redhat.com> References: <20161117222441.31464-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 17 Nov 2016 22:24:50 +0000 (UTC) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In some cases an LED is controlled through a hardwired (taken care of in firmware outside of the kernels control) trigger. Add an LED_TRIGGER_READ_ONLY flag for this and disallow user-space changing the trigger when this flag is set. Signed-off-by: Hans de Goede --- Changes in v5: -This is a new patch in v5 of this patch-set --- drivers/leds/led-class.c | 2 +- drivers/leds/led-triggers.c | 5 +++++ include/linux/leds.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 326ee6e..56f32cc 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -54,7 +54,7 @@ static ssize_t brightness_store(struct device *dev, if (ret) goto unlock; - if (state == LED_OFF) + if (state == LED_OFF && !(led_cdev->flags & LED_TRIGGER_READ_ONLY)) led_trigger_remove(led_cdev); led_set_brightness(led_cdev, state); diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index d2ed9c2..9669104 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -37,6 +37,11 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, struct led_trigger *trig; int ret = count; + if (led_cdev->flags & LED_TRIGGER_READ_ONLY) { + dev_err(led_cdev->dev, "Error this led triggers is hardwired and cannot be changed\n"); + return -EINVAL; + } + mutex_lock(&led_cdev->led_access); if (led_sysfs_is_disabled(led_cdev)) { diff --git a/include/linux/leds.h b/include/linux/leds.h index 870b8c2..e076b74 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -47,6 +47,7 @@ struct led_classdev { #define LED_DEV_CAP_FLASH (1 << 18) #define LED_HW_PLUGGABLE (1 << 19) #define LED_PANIC_INDICATOR (1 << 20) +#define LED_TRIGGER_READ_ONLY (1 << 21) /* set_brightness_work / blink_timer flags, atomic, private. */ unsigned long work_flags;