All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v10 0/3] leds: trigger: implement a tty trigger
@ 2020-12-18 10:42 Uwe Kleine-König
  2020-12-18 10:42 ` [PATCH v10 1/3] tty: rename tty_kopen() and add new function tty_kopen_shared() Uwe Kleine-König
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2020-12-18 10:42 UTC (permalink / raw)
  To: Jacek Anaszewski, Pavel Machek, Dan Murphy, Greg Kroah-Hartman,
	Jiri Slaby
  Cc: linux-serial, linux-leds, linux-kernel, kernel, Johan Hovold,
	Uwe Kleine-König

From: Uwe Kleine-König <uwe@kleine-koenig.org>

Hello,

here comes v10 of this series. Changes compared to v9 sent with
Message-Id: 20201018204022.910815-1-u.kleine-koenig@pengutronix.de in
October:

 - Bump date and kernel version in ABI doc
 - Fix double unlock in error path; found by Pavel
 - Don't stop the workqueue in ttyname_store() to
   fix error behaviour on memory allocation failure.
   Now it continues with the previous configuration instead of
   stopping. Also found by Pavel.

Unaddressed review comments by Pavel are:

 - Unused assignment to len in ttyname_show
   This is wrong
 - "Poll every 100 msec... Hmm.... Okay, I guess?"
   Yes, I think there is no way around this given the trigger uses
   polling. There is no easy way to get notified instead.
 - "Are you sure about LED_ON [in the worker]? It should use current
   brightness selected by brightness file..."
   I found no consistent behaviour in other triggers. ledtrig-gpio
   implements a dedicated "desired_brightness" sysfs file, several use
   led_cdev->blink_brightness (via led_trigger_blink_oneshot),
   ledtrig-cpu uses led_trigger_event with LED_FULL.
 - "How is [the data initialized in ledtrig_tty_activate()] protected
   from concurrent access from sysfs?"
   I think there is no need to protect this. But I'm not sure I
   understood the question correctly, so please recheck and if needed
   point out the problem you see in more detail.

Uwe Kleine-König (3):
  tty: rename tty_kopen() and add new function tty_kopen_shared()
  tty: new helper function tty_get_icount()
  leds: trigger: implement a tty trigger

 .../ABI/testing/sysfs-class-led-trigger-tty   |   6 +
 drivers/accessibility/speakup/spk_ttyio.c     |   2 +-
 drivers/leds/trigger/Kconfig                  |   9 +
 drivers/leds/trigger/Makefile                 |   1 +
 drivers/leds/trigger/ledtrig-tty.c            | 188 ++++++++++++++++++
 drivers/tty/tty_io.c                          |  85 ++++++--
 include/linux/tty.h                           |   7 +-
 7 files changed, 273 insertions(+), 25 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-tty
 create mode 100644 drivers/leds/trigger/ledtrig-tty.c

-- 
2.29.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v10 1/3] tty: rename tty_kopen() and add new function tty_kopen_shared()
  2020-12-18 10:42 [PATCH v10 0/3] leds: trigger: implement a tty trigger Uwe Kleine-König
@ 2020-12-18 10:42 ` Uwe Kleine-König
  2020-12-18 10:42 ` [PATCH v10 2/3] tty: new helper function tty_get_icount() Uwe Kleine-König
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2020-12-18 10:42 UTC (permalink / raw)
  To: Jacek Anaszewski, Pavel Machek, Dan Murphy, Greg Kroah-Hartman,
	Jiri Slaby
  Cc: linux-serial, linux-leds, linux-kernel, kernel, Johan Hovold

Introduce a new function tty_kopen_shared() that yields a struct
tty_struct. The semantic difference to tty_kopen() is that the tty is
expected to be used already. So rename tty_kopen() to
tty_kopen_exclusive() for clearness, adapt the single user and put the
common code in a new static helper function.

tty_kopen_shared is to be used to implement an LED trigger for tty
devices in one of the next patches.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/accessibility/speakup/spk_ttyio.c |  2 +-
 drivers/tty/tty_io.c                      | 56 +++++++++++++++--------
 include/linux/tty.h                       |  5 +-
 3 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/drivers/accessibility/speakup/spk_ttyio.c b/drivers/accessibility/speakup/spk_ttyio.c
index 6284aff434a1..835d17455fcd 100644
--- a/drivers/accessibility/speakup/spk_ttyio.c
+++ b/drivers/accessibility/speakup/spk_ttyio.c
@@ -152,7 +152,7 @@ static int spk_ttyio_initialise_ldisc(struct spk_synth *synth)
 	if (ret)
 		return ret;
 
-	tty = tty_kopen(dev);
+	tty = tty_kopen_exclusive(dev);
 	if (IS_ERR(tty))
 		return PTR_ERR(tty);
 
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 56ade99ef99f..d0c1f97adc17 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1873,22 +1873,7 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
 	return driver;
 }
 
-/**
- *	tty_kopen	-	open a tty device for kernel
- *	@device: dev_t of device to open
- *
- *	Opens tty exclusively for kernel. Performs the driver lookup,
- *	makes sure it's not already opened and performs the first-time
- *	tty initialization.
- *
- *	Returns the locked initialized &tty_struct
- *
- *	Claims the global tty_mutex to serialize:
- *	  - concurrent first-time tty initialization
- *	  - concurrent tty driver removal w/ lookup
- *	  - concurrent tty removal from driver table
- */
-struct tty_struct *tty_kopen(dev_t device)
+static struct tty_struct *tty_kopen(dev_t device, int shared)
 {
 	struct tty_struct *tty;
 	struct tty_driver *driver;
@@ -1903,7 +1888,7 @@ struct tty_struct *tty_kopen(dev_t device)
 
 	/* check whether we're reopening an existing tty */
 	tty = tty_driver_lookup_tty(driver, NULL, index);
-	if (IS_ERR(tty))
+	if (IS_ERR(tty) || shared)
 		goto out;
 
 	if (tty) {
@@ -1921,7 +1906,42 @@ struct tty_struct *tty_kopen(dev_t device)
 	tty_driver_kref_put(driver);
 	return tty;
 }
-EXPORT_SYMBOL_GPL(tty_kopen);
+
+/**
+ *	tty_kopen_exclusive	-	open a tty device for kernel
+ *	@device: dev_t of device to open
+ *
+ *	Opens tty exclusively for kernel. Performs the driver lookup,
+ *	makes sure it's not already opened and performs the first-time
+ *	tty initialization.
+ *
+ *	Returns the locked initialized &tty_struct
+ *
+ *	Claims the global tty_mutex to serialize:
+ *	  - concurrent first-time tty initialization
+ *	  - concurrent tty driver removal w/ lookup
+ *	  - concurrent tty removal from driver table
+ */
+struct tty_struct *tty_kopen_exclusive(dev_t device)
+{
+	return tty_kopen(device, 0);
+}
+EXPORT_SYMBOL_GPL(tty_kopen_exclusive);
+
+/**
+ *	tty_kopen_shared	-	open a tty device for shared in-kernel use
+ *	@device: dev_t of device to open
+ *
+ *	Opens an already existing tty for in-kernel use. Compared to
+ *	tty_kopen_exclusive() above it doesn't ensure to be the only user.
+ *
+ *	Locking is identical to tty_kopen() above.
+ */
+struct tty_struct *tty_kopen_shared(dev_t device)
+{
+	return tty_kopen(device, 1);
+}
+EXPORT_SYMBOL_GPL(tty_kopen_shared);
 
 /**
  *	tty_open_by_driver	-	open a tty device
diff --git a/include/linux/tty.h b/include/linux/tty.h
index eb33d948788c..7c3b5f156f03 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -417,7 +417,8 @@ extern struct tty_struct *get_current_tty(void);
 /* tty_io.c */
 extern int __init tty_init(void);
 extern const char *tty_name(const struct tty_struct *tty);
-extern struct tty_struct *tty_kopen(dev_t device);
+extern struct tty_struct *tty_kopen_exclusive(dev_t device);
+extern struct tty_struct *tty_kopen_shared(dev_t device);
 extern void tty_kclose(struct tty_struct *tty);
 extern int tty_dev_name_to_number(const char *name, dev_t *number);
 extern int tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout);
@@ -442,7 +443,7 @@ static inline int __init tty_init(void)
 { return 0; }
 static inline const char *tty_name(const struct tty_struct *tty)
 { return "(none)"; }
-static inline struct tty_struct *tty_kopen(dev_t device)
+static inline struct tty_struct *tty_kopen_exclusive(dev_t device)
 { return ERR_PTR(-ENODEV); }
 static inline void tty_kclose(struct tty_struct *tty)
 { }
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v10 2/3] tty: new helper function tty_get_icount()
  2020-12-18 10:42 [PATCH v10 0/3] leds: trigger: implement a tty trigger Uwe Kleine-König
  2020-12-18 10:42 ` [PATCH v10 1/3] tty: rename tty_kopen() and add new function tty_kopen_shared() Uwe Kleine-König
@ 2020-12-18 10:42 ` Uwe Kleine-König
  2020-12-18 10:42 ` [PATCH v10 3/3] leds: trigger: implement a tty trigger Uwe Kleine-König
  2020-12-28 15:10 ` [PATCH v10 0/3] " Greg Kroah-Hartman
  3 siblings, 0 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2020-12-18 10:42 UTC (permalink / raw)
  To: Jacek Anaszewski, Pavel Machek, Dan Murphy, Greg Kroah-Hartman,
	Jiri Slaby
  Cc: linux-serial, linux-leds, linux-kernel, kernel, Johan Hovold

For a given struct tty_struct this yields the corresponding statistics
about sent and received characters (and some more) which is needed to
implement an LED trigger for tty devices.

The new function is then used to simplify tty_tiocgicount().

Reviewed-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/tty/tty_io.c | 29 +++++++++++++++++++++++++----
 include/linux/tty.h  |  2 ++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index d0c1f97adc17..61b179f2ae42 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2486,15 +2486,36 @@ static int tty_tiocmset(struct tty_struct *tty, unsigned int cmd,
 	return tty->ops->tiocmset(tty, set, clear);
 }
 
+/**
+ *	tty_get_icount		-	get tty statistics
+ *	@tty: tty device
+ *	@icount: output parameter
+ *
+ *	Gets a copy of the tty's icount statistics.
+ *
+ *	Locking: none (up to the driver)
+ */
+int tty_get_icount(struct tty_struct *tty,
+		   struct serial_icounter_struct *icount)
+{
+	memset(icount, 0, sizeof(*icount));
+
+	if (tty->ops->get_icount)
+		return tty->ops->get_icount(tty, icount);
+	else
+		return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(tty_get_icount);
+
 static int tty_tiocgicount(struct tty_struct *tty, void __user *arg)
 {
-	int retval = -EINVAL;
 	struct serial_icounter_struct icount;
-	memset(&icount, 0, sizeof(icount));
-	if (tty->ops->get_icount)
-		retval = tty->ops->get_icount(tty, &icount);
+	int retval;
+
+	retval = tty_get_icount(tty, &icount);
 	if (retval != 0)
 		return retval;
+
 	if (copy_to_user(arg, &icount, sizeof(icount)))
 		return -EFAULT;
 	return 0;
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 7c3b5f156f03..3c689e9cd494 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -501,6 +501,8 @@ extern void tty_unthrottle(struct tty_struct *tty);
 extern int tty_throttle_safe(struct tty_struct *tty);
 extern int tty_unthrottle_safe(struct tty_struct *tty);
 extern int tty_do_resize(struct tty_struct *tty, struct winsize *ws);
+extern int tty_get_icount(struct tty_struct *tty,
+			  struct serial_icounter_struct *icount);
 extern int is_current_pgrp_orphaned(void);
 extern void tty_hangup(struct tty_struct *tty);
 extern void tty_vhangup(struct tty_struct *tty);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v10 3/3] leds: trigger: implement a tty trigger
  2020-12-18 10:42 [PATCH v10 0/3] leds: trigger: implement a tty trigger Uwe Kleine-König
  2020-12-18 10:42 ` [PATCH v10 1/3] tty: rename tty_kopen() and add new function tty_kopen_shared() Uwe Kleine-König
  2020-12-18 10:42 ` [PATCH v10 2/3] tty: new helper function tty_get_icount() Uwe Kleine-König
@ 2020-12-18 10:42 ` Uwe Kleine-König
  2021-01-13 16:16   ` Greg Kroah-Hartman
  2020-12-28 15:10 ` [PATCH v10 0/3] " Greg Kroah-Hartman
  3 siblings, 1 reply; 13+ messages in thread
From: Uwe Kleine-König @ 2020-12-18 10:42 UTC (permalink / raw)
  To: Jacek Anaszewski, Pavel Machek, Dan Murphy, Greg Kroah-Hartman,
	Jiri Slaby
  Cc: linux-serial, linux-leds, linux-kernel, kernel, Johan Hovold

Usage is as follows:

	myled=ledname
	tty=ttyS0

	echo tty > /sys/class/leds/$myled/trigger
	echo $tty > /sys/class/leds/$myled/ttyname

. When this new trigger is active it periodically checks the tty's
statistics and when it changed since the last check the led is flashed
once.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 .../ABI/testing/sysfs-class-led-trigger-tty   |   6 +
 drivers/leds/trigger/Kconfig                  |   9 +
 drivers/leds/trigger/Makefile                 |   1 +
 drivers/leds/trigger/ledtrig-tty.c            | 188 ++++++++++++++++++
 4 files changed, 204 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-tty
 create mode 100644 drivers/leds/trigger/ledtrig-tty.c

diff --git a/Documentation/ABI/testing/sysfs-class-led-trigger-tty b/Documentation/ABI/testing/sysfs-class-led-trigger-tty
new file mode 100644
index 000000000000..2bf6b24e781b
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-led-trigger-tty
@@ -0,0 +1,6 @@
+What:		/sys/class/leds/<led>/ttyname
+Date:		Dec 2020
+KernelVersion:	5.10
+Contact:	linux-leds@vger.kernel.org
+Description:
+		Specifies the tty device name of the triggering tty
diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
index ce9429ca6dde..b77a01bd27f4 100644
--- a/drivers/leds/trigger/Kconfig
+++ b/drivers/leds/trigger/Kconfig
@@ -144,4 +144,13 @@ config LEDS_TRIGGER_AUDIO
 	  the audio mute and mic-mute changes.
 	  If unsure, say N
 
+config LEDS_TRIGGER_TTY
+	tristate "LED Trigger for TTY devices"
+	depends on TTY
+	help
+	  This allows LEDs to be controlled by activity on ttys which includes
+	  serial devices like /dev/ttyS0.
+
+	  When build as a module this driver will be called ledtrig-tty.
+
 endif # LEDS_TRIGGERS
diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile
index 733a83e2a718..25c4db97cdd4 100644
--- a/drivers/leds/trigger/Makefile
+++ b/drivers/leds/trigger/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_LEDS_TRIGGER_PANIC)	+= ledtrig-panic.o
 obj-$(CONFIG_LEDS_TRIGGER_NETDEV)	+= ledtrig-netdev.o
 obj-$(CONFIG_LEDS_TRIGGER_PATTERN)	+= ledtrig-pattern.o
 obj-$(CONFIG_LEDS_TRIGGER_AUDIO)	+= ledtrig-audio.o
+obj-$(CONFIG_LEDS_TRIGGER_TTY)		+= ledtrig-tty.o
diff --git a/drivers/leds/trigger/ledtrig-tty.c b/drivers/leds/trigger/ledtrig-tty.c
new file mode 100644
index 000000000000..c1e87c0d23c3
--- /dev/null
+++ b/drivers/leds/trigger/ledtrig-tty.c
@@ -0,0 +1,188 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/delay.h>
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/tty.h>
+#include <uapi/linux/serial.h>
+
+struct ledtrig_tty_data {
+	struct led_classdev *led_cdev;
+	struct delayed_work dwork;
+	struct mutex mutex;
+	const char *ttyname;
+	struct tty_struct *tty;
+	int rx, tx;
+};
+
+static void ledtrig_tty_halt(struct ledtrig_tty_data *trigger_data)
+{
+	cancel_delayed_work_sync(&trigger_data->dwork);
+}
+
+static void ledtrig_tty_restart(struct ledtrig_tty_data *trigger_data)
+{
+	schedule_delayed_work(&trigger_data->dwork, 0);
+}
+
+static ssize_t ttyname_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct ledtrig_tty_data *trigger_data = led_trigger_get_drvdata(dev);
+	ssize_t len = 0;
+
+	mutex_lock(&trigger_data->mutex);
+
+	if (trigger_data->ttyname)
+		len = sprintf(buf, "%s\n", trigger_data->ttyname);
+
+	mutex_unlock(&trigger_data->mutex);
+
+	return len;
+}
+
+static ssize_t ttyname_store(struct device *dev,
+			     struct device_attribute *attr, const char *buf,
+			     size_t size)
+{
+	struct ledtrig_tty_data *trigger_data = led_trigger_get_drvdata(dev);
+	char *ttyname;
+	ssize_t ret = size;
+	bool running;
+
+	if (size > 0 && buf[size - 1] == '\n')
+		size -= 1;
+
+	if (size) {
+		ttyname = kmemdup_nul(buf, size, GFP_KERNEL);
+		if (!ttyname) {
+			ret = -ENOMEM;
+			goto out_unlock;
+		}
+	} else {
+		ttyname = NULL;
+	}
+
+	mutex_lock(&trigger_data->mutex);
+
+	running = trigger_data->ttyname != NULL;
+
+	kfree(trigger_data->ttyname);
+	tty_kref_put(trigger_data->tty);
+	trigger_data->tty = NULL;
+
+	trigger_data->ttyname = ttyname;
+
+out_unlock:
+	mutex_unlock(&trigger_data->mutex);
+
+	if (ttyname && !running)
+		ledtrig_tty_restart(trigger_data);
+
+	return ret;
+}
+static DEVICE_ATTR_RW(ttyname);
+
+static void ledtrig_tty_work(struct work_struct *work)
+{
+	struct ledtrig_tty_data *trigger_data =
+		container_of(work, struct ledtrig_tty_data, dwork.work);
+	struct serial_icounter_struct icount;
+	int ret;
+
+	mutex_lock(&trigger_data->mutex);
+
+	if (!trigger_data->ttyname) {
+		/* exit without rescheduling */
+		mutex_unlock(&trigger_data->mutex);
+		return;
+	}
+
+	/* try to get the tty corresponding to $ttyname */
+	if (!trigger_data->tty) {
+		dev_t devno;
+		struct tty_struct *tty;
+		int ret;
+
+		ret = tty_dev_name_to_number(trigger_data->ttyname, &devno);
+		if (ret < 0)
+			/*
+			 * A device with this name might appear later, so keep
+			 * retrying.
+			 */
+			goto out;
+
+		tty = tty_kopen_shared(devno);
+		if (IS_ERR(tty) || !tty)
+			/* What to do? retry or abort */
+			goto out;
+
+		trigger_data->tty = tty;
+	}
+
+	ret = tty_get_icount(trigger_data->tty, &icount);
+	if (ret) {
+		dev_info(trigger_data->tty->dev, "Failed to get icount, stopped polling\n");
+		mutex_unlock(&trigger_data->mutex);
+		return;
+	}
+
+	if (icount.rx != trigger_data->rx ||
+	    icount.tx != trigger_data->tx) {
+		led_set_brightness(trigger_data->led_cdev, LED_ON);
+
+		trigger_data->rx = icount.rx;
+		trigger_data->tx = icount.tx;
+	} else {
+		led_set_brightness(trigger_data->led_cdev, LED_OFF);
+	}
+
+out:
+	mutex_unlock(&trigger_data->mutex);
+	schedule_delayed_work(&trigger_data->dwork, msecs_to_jiffies(100));
+}
+
+static struct attribute *ledtrig_tty_attrs[] = {
+	&dev_attr_ttyname.attr,
+	NULL
+};
+ATTRIBUTE_GROUPS(ledtrig_tty);
+
+static int ledtrig_tty_activate(struct led_classdev *led_cdev)
+{
+	struct ledtrig_tty_data *trigger_data;
+
+	trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
+	if (!trigger_data)
+		return -ENOMEM;
+
+	led_set_trigger_data(led_cdev, trigger_data);
+
+	INIT_DELAYED_WORK(&trigger_data->dwork, ledtrig_tty_work);
+	trigger_data->led_cdev = led_cdev;
+	mutex_init(&trigger_data->mutex);
+
+	return 0;
+}
+
+static void ledtrig_tty_deactivate(struct led_classdev *led_cdev)
+{
+	struct ledtrig_tty_data *trigger_data = led_get_trigger_data(led_cdev);
+
+	cancel_delayed_work_sync(&trigger_data->dwork);
+
+	kfree(trigger_data);
+}
+
+static struct led_trigger ledtrig_tty = {
+	.name = "tty",
+	.activate = ledtrig_tty_activate,
+	.deactivate = ledtrig_tty_deactivate,
+	.groups = ledtrig_tty_groups,
+};
+module_led_trigger(ledtrig_tty);
+
+MODULE_AUTHOR("Uwe Kleine-König <u.kleine-koenig@pengutronix.de>");
+MODULE_DESCRIPTION("UART LED trigger");
+MODULE_LICENSE("GPL v2");
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v10 0/3] leds: trigger: implement a tty trigger
  2020-12-18 10:42 [PATCH v10 0/3] leds: trigger: implement a tty trigger Uwe Kleine-König
                   ` (2 preceding siblings ...)
  2020-12-18 10:42 ` [PATCH v10 3/3] leds: trigger: implement a tty trigger Uwe Kleine-König
@ 2020-12-28 15:10 ` Greg Kroah-Hartman
  3 siblings, 0 replies; 13+ messages in thread
From: Greg Kroah-Hartman @ 2020-12-28 15:10 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jacek Anaszewski, Pavel Machek, Dan Murphy, Jiri Slaby,
	linux-serial, linux-leds, linux-kernel, kernel, Johan Hovold,
	Uwe Kleine-König

On Fri, Dec 18, 2020 at 11:42:43AM +0100, Uwe Kleine-König wrote:
> From: Uwe Kleine-König <uwe@kleine-koenig.org>
> 
> Hello,
> 
> here comes v10 of this series. Changes compared to v9 sent with
> Message-Id: 20201018204022.910815-1-u.kleine-koenig@pengutronix.de in
> October:

First 2 patches now applied to my tree.

If I get an ack from the LED maintainer(s), I'll be glad to also queue
up the third one too.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v10 3/3] leds: trigger: implement a tty trigger
  2020-12-18 10:42 ` [PATCH v10 3/3] leds: trigger: implement a tty trigger Uwe Kleine-König
@ 2021-01-13 16:16   ` Greg Kroah-Hartman
  2021-01-13 17:30     ` [PATCH v11] " Uwe Kleine-König
  0 siblings, 1 reply; 13+ messages in thread
From: Greg Kroah-Hartman @ 2021-01-13 16:16 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jacek Anaszewski, Pavel Machek, Dan Murphy, Jiri Slaby,
	linux-serial, linux-leds, linux-kernel, kernel, Johan Hovold

On Fri, Dec 18, 2020 at 11:42:46AM +0100, Uwe Kleine-König wrote:
> Usage is as follows:
> 
> 	myled=ledname
> 	tty=ttyS0
> 
> 	echo tty > /sys/class/leds/$myled/trigger
> 	echo $tty > /sys/class/leds/$myled/ttyname
> 
> . When this new trigger is active it periodically checks the tty's
> statistics and when it changed since the last check the led is flashed
> once.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  .../ABI/testing/sysfs-class-led-trigger-tty   |   6 +
>  drivers/leds/trigger/Kconfig                  |   9 +
>  drivers/leds/trigger/Makefile                 |   1 +
>  drivers/leds/trigger/ledtrig-tty.c            | 188 ++++++++++++++++++
>  4 files changed, 204 insertions(+)
>  create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-tty
>  create mode 100644 drivers/leds/trigger/ledtrig-tty.c
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-led-trigger-tty b/Documentation/ABI/testing/sysfs-class-led-trigger-tty
> new file mode 100644
> index 000000000000..2bf6b24e781b
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-class-led-trigger-tty
> @@ -0,0 +1,6 @@
> +What:		/sys/class/leds/<led>/ttyname
> +Date:		Dec 2020
> +KernelVersion:	5.10
> +Contact:	linux-leds@vger.kernel.org
> +Description:
> +		Specifies the tty device name of the triggering tty
> diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
> index ce9429ca6dde..b77a01bd27f4 100644
> --- a/drivers/leds/trigger/Kconfig
> +++ b/drivers/leds/trigger/Kconfig
> @@ -144,4 +144,13 @@ config LEDS_TRIGGER_AUDIO
>  	  the audio mute and mic-mute changes.
>  	  If unsure, say N
>  
> +config LEDS_TRIGGER_TTY
> +	tristate "LED Trigger for TTY devices"
> +	depends on TTY
> +	help
> +	  This allows LEDs to be controlled by activity on ttys which includes
> +	  serial devices like /dev/ttyS0.
> +
> +	  When build as a module this driver will be called ledtrig-tty.
> +
>  endif # LEDS_TRIGGERS
> diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile
> index 733a83e2a718..25c4db97cdd4 100644
> --- a/drivers/leds/trigger/Makefile
> +++ b/drivers/leds/trigger/Makefile
> @@ -15,3 +15,4 @@ obj-$(CONFIG_LEDS_TRIGGER_PANIC)	+= ledtrig-panic.o
>  obj-$(CONFIG_LEDS_TRIGGER_NETDEV)	+= ledtrig-netdev.o
>  obj-$(CONFIG_LEDS_TRIGGER_PATTERN)	+= ledtrig-pattern.o
>  obj-$(CONFIG_LEDS_TRIGGER_AUDIO)	+= ledtrig-audio.o
> +obj-$(CONFIG_LEDS_TRIGGER_TTY)		+= ledtrig-tty.o
> diff --git a/drivers/leds/trigger/ledtrig-tty.c b/drivers/leds/trigger/ledtrig-tty.c
> new file mode 100644
> index 000000000000..c1e87c0d23c3
> --- /dev/null
> +++ b/drivers/leds/trigger/ledtrig-tty.c
> @@ -0,0 +1,188 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/delay.h>
> +#include <linux/leds.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/tty.h>
> +#include <uapi/linux/serial.h>
> +
> +struct ledtrig_tty_data {
> +	struct led_classdev *led_cdev;
> +	struct delayed_work dwork;
> +	struct mutex mutex;
> +	const char *ttyname;
> +	struct tty_struct *tty;
> +	int rx, tx;
> +};
> +
> +static void ledtrig_tty_halt(struct ledtrig_tty_data *trigger_data)
> +{
> +	cancel_delayed_work_sync(&trigger_data->dwork);
> +}

This causes the following build warning with the patch applied:

drivers/leds/trigger/ledtrig-tty.c:19:13: warning: ‘ledtrig_tty_halt’ defined but not used [-Wunused-function]
   19 | static void ledtrig_tty_halt(struct ledtrig_tty_data *trigger_data)
      |             ^~~~~~~~~~~~~~~~

Can you fix this up and just resend this patch (the other 2 are already
in my tree), so that I can queue it up?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v11] leds: trigger: implement a tty trigger
  2021-01-13 16:16   ` Greg Kroah-Hartman
@ 2021-01-13 17:30     ` Uwe Kleine-König
  2021-01-13 18:34       ` Greg Kroah-Hartman
  2021-02-18 13:37       ` Pavel Machek
  0 siblings, 2 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2021-01-13 17:30 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Pavel Machek, linux-kernel, Johan Hovold, Jacek Anaszewski,
	linux-serial, Jiri Slaby, kernel, linux-leds, Dan Murphy

[-- Attachment #1: Type: text/plain, Size: 8359 bytes --]

Usage is as follows:

	myled=ledname
	tty=ttyS0

	echo tty > /sys/class/leds/$myled/trigger
	echo $tty > /sys/class/leds/$myled/ttyname

. When this new trigger is active it periodically checks the tty's
statistics and when it changed since the last check the led is flashed
once.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

On Wed, Jan 13, 2021 at 05:16:00PM +0100, Greg Kroah-Hartman wrote:
> This causes the following build warning with the patch applied:
> 
> drivers/leds/trigger/ledtrig-tty.c:19:13: warning: ‘ledtrig_tty_halt’ defined but not used [-Wunused-function]
>    19 | static void ledtrig_tty_halt(struct ledtrig_tty_data *trigger_data)
>       |             ^~~~~~~~~~~~~~~~
> 
> Can you fix this up and just resend this patch (the other 2 are already
> in my tree),

oh indeed. Thanks for catching this and so preventing me still more
shame when I have to receive a dozen or so patches that fix this :-)
Droping this function is the only change since v10.

> so that I can queue it up?

Oh, so you are LED maintainer now? My congratulations.
(Honestly, do you plan to apply this without their ack? Not that I'm
against you doing that, I'm happy if I can archive this patch series as
done, but I'm a bit surprised.)

Best regards
Uwe

 .../ABI/testing/sysfs-class-led-trigger-tty   |   6 +
 drivers/leds/trigger/Kconfig                  |   9 +
 drivers/leds/trigger/Makefile                 |   1 +
 drivers/leds/trigger/ledtrig-tty.c            | 183 ++++++++++++++++++
 4 files changed, 199 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-tty
 create mode 100644 drivers/leds/trigger/ledtrig-tty.c

diff --git a/Documentation/ABI/testing/sysfs-class-led-trigger-tty b/Documentation/ABI/testing/sysfs-class-led-trigger-tty
new file mode 100644
index 000000000000..2bf6b24e781b
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-led-trigger-tty
@@ -0,0 +1,6 @@
+What:		/sys/class/leds/<led>/ttyname
+Date:		Dec 2020
+KernelVersion:	5.10
+Contact:	linux-leds@vger.kernel.org
+Description:
+		Specifies the tty device name of the triggering tty
diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
index ce9429ca6dde..b77a01bd27f4 100644
--- a/drivers/leds/trigger/Kconfig
+++ b/drivers/leds/trigger/Kconfig
@@ -144,4 +144,13 @@ config LEDS_TRIGGER_AUDIO
 	  the audio mute and mic-mute changes.
 	  If unsure, say N
 
+config LEDS_TRIGGER_TTY
+	tristate "LED Trigger for TTY devices"
+	depends on TTY
+	help
+	  This allows LEDs to be controlled by activity on ttys which includes
+	  serial devices like /dev/ttyS0.
+
+	  When build as a module this driver will be called ledtrig-tty.
+
 endif # LEDS_TRIGGERS
diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile
index 733a83e2a718..25c4db97cdd4 100644
--- a/drivers/leds/trigger/Makefile
+++ b/drivers/leds/trigger/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_LEDS_TRIGGER_PANIC)	+= ledtrig-panic.o
 obj-$(CONFIG_LEDS_TRIGGER_NETDEV)	+= ledtrig-netdev.o
 obj-$(CONFIG_LEDS_TRIGGER_PATTERN)	+= ledtrig-pattern.o
 obj-$(CONFIG_LEDS_TRIGGER_AUDIO)	+= ledtrig-audio.o
+obj-$(CONFIG_LEDS_TRIGGER_TTY)		+= ledtrig-tty.o
diff --git a/drivers/leds/trigger/ledtrig-tty.c b/drivers/leds/trigger/ledtrig-tty.c
new file mode 100644
index 000000000000..d2ab6ab080ac
--- /dev/null
+++ b/drivers/leds/trigger/ledtrig-tty.c
@@ -0,0 +1,183 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/delay.h>
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/tty.h>
+#include <uapi/linux/serial.h>
+
+struct ledtrig_tty_data {
+	struct led_classdev *led_cdev;
+	struct delayed_work dwork;
+	struct mutex mutex;
+	const char *ttyname;
+	struct tty_struct *tty;
+	int rx, tx;
+};
+
+static void ledtrig_tty_restart(struct ledtrig_tty_data *trigger_data)
+{
+	schedule_delayed_work(&trigger_data->dwork, 0);
+}
+
+static ssize_t ttyname_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct ledtrig_tty_data *trigger_data = led_trigger_get_drvdata(dev);
+	ssize_t len = 0;
+
+	mutex_lock(&trigger_data->mutex);
+
+	if (trigger_data->ttyname)
+		len = sprintf(buf, "%s\n", trigger_data->ttyname);
+
+	mutex_unlock(&trigger_data->mutex);
+
+	return len;
+}
+
+static ssize_t ttyname_store(struct device *dev,
+			     struct device_attribute *attr, const char *buf,
+			     size_t size)
+{
+	struct ledtrig_tty_data *trigger_data = led_trigger_get_drvdata(dev);
+	char *ttyname;
+	ssize_t ret = size;
+	bool running;
+
+	if (size > 0 && buf[size - 1] == '\n')
+		size -= 1;
+
+	if (size) {
+		ttyname = kmemdup_nul(buf, size, GFP_KERNEL);
+		if (!ttyname) {
+			ret = -ENOMEM;
+			goto out_unlock;
+		}
+	} else {
+		ttyname = NULL;
+	}
+
+	mutex_lock(&trigger_data->mutex);
+
+	running = trigger_data->ttyname != NULL;
+
+	kfree(trigger_data->ttyname);
+	tty_kref_put(trigger_data->tty);
+	trigger_data->tty = NULL;
+
+	trigger_data->ttyname = ttyname;
+
+out_unlock:
+	mutex_unlock(&trigger_data->mutex);
+
+	if (ttyname && !running)
+		ledtrig_tty_restart(trigger_data);
+
+	return ret;
+}
+static DEVICE_ATTR_RW(ttyname);
+
+static void ledtrig_tty_work(struct work_struct *work)
+{
+	struct ledtrig_tty_data *trigger_data =
+		container_of(work, struct ledtrig_tty_data, dwork.work);
+	struct serial_icounter_struct icount;
+	int ret;
+
+	mutex_lock(&trigger_data->mutex);
+
+	if (!trigger_data->ttyname) {
+		/* exit without rescheduling */
+		mutex_unlock(&trigger_data->mutex);
+		return;
+	}
+
+	/* try to get the tty corresponding to $ttyname */
+	if (!trigger_data->tty) {
+		dev_t devno;
+		struct tty_struct *tty;
+		int ret;
+
+		ret = tty_dev_name_to_number(trigger_data->ttyname, &devno);
+		if (ret < 0)
+			/*
+			 * A device with this name might appear later, so keep
+			 * retrying.
+			 */
+			goto out;
+
+		tty = tty_kopen_shared(devno);
+		if (IS_ERR(tty) || !tty)
+			/* What to do? retry or abort */
+			goto out;
+
+		trigger_data->tty = tty;
+	}
+
+	ret = tty_get_icount(trigger_data->tty, &icount);
+	if (ret) {
+		dev_info(trigger_data->tty->dev, "Failed to get icount, stopped polling\n");
+		mutex_unlock(&trigger_data->mutex);
+		return;
+	}
+
+	if (icount.rx != trigger_data->rx ||
+	    icount.tx != trigger_data->tx) {
+		led_set_brightness(trigger_data->led_cdev, LED_ON);
+
+		trigger_data->rx = icount.rx;
+		trigger_data->tx = icount.tx;
+	} else {
+		led_set_brightness(trigger_data->led_cdev, LED_OFF);
+	}
+
+out:
+	mutex_unlock(&trigger_data->mutex);
+	schedule_delayed_work(&trigger_data->dwork, msecs_to_jiffies(100));
+}
+
+static struct attribute *ledtrig_tty_attrs[] = {
+	&dev_attr_ttyname.attr,
+	NULL
+};
+ATTRIBUTE_GROUPS(ledtrig_tty);
+
+static int ledtrig_tty_activate(struct led_classdev *led_cdev)
+{
+	struct ledtrig_tty_data *trigger_data;
+
+	trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
+	if (!trigger_data)
+		return -ENOMEM;
+
+	led_set_trigger_data(led_cdev, trigger_data);
+
+	INIT_DELAYED_WORK(&trigger_data->dwork, ledtrig_tty_work);
+	trigger_data->led_cdev = led_cdev;
+	mutex_init(&trigger_data->mutex);
+
+	return 0;
+}
+
+static void ledtrig_tty_deactivate(struct led_classdev *led_cdev)
+{
+	struct ledtrig_tty_data *trigger_data = led_get_trigger_data(led_cdev);
+
+	cancel_delayed_work_sync(&trigger_data->dwork);
+
+	kfree(trigger_data);
+}
+
+static struct led_trigger ledtrig_tty = {
+	.name = "tty",
+	.activate = ledtrig_tty_activate,
+	.deactivate = ledtrig_tty_deactivate,
+	.groups = ledtrig_tty_groups,
+};
+module_led_trigger(ledtrig_tty);
+
+MODULE_AUTHOR("Uwe Kleine-König <u.kleine-koenig@pengutronix.de>");
+MODULE_DESCRIPTION("UART LED trigger");
+MODULE_LICENSE("GPL v2");

base-commit: 5c8fe583cce542aa0b84adc939ce85293de36e5e
prerequisite-patch-id: a2c3eea0944a3ae222a4429ba4983d24bea8e0fa
prerequisite-patch-id: 8203736a5395e3deef08add27f70f0f00b845d43
-- 
2.29.2

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v11] leds: trigger: implement a tty trigger
  2021-01-13 17:30     ` [PATCH v11] " Uwe Kleine-König
@ 2021-01-13 18:34       ` Greg Kroah-Hartman
  2021-02-18 13:33         ` Pavel Machek
  2021-02-18 13:37       ` Pavel Machek
  1 sibling, 1 reply; 13+ messages in thread
From: Greg Kroah-Hartman @ 2021-01-13 18:34 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Pavel Machek, linux-kernel, Johan Hovold, Jacek Anaszewski,
	linux-serial, Jiri Slaby, kernel, linux-leds, Dan Murphy

On Wed, Jan 13, 2021 at 06:30:18PM +0100, Uwe Kleine-König wrote:
> Usage is as follows:
> 
> 	myled=ledname
> 	tty=ttyS0
> 
> 	echo tty > /sys/class/leds/$myled/trigger
> 	echo $tty > /sys/class/leds/$myled/ttyname
> 
> . When this new trigger is active it periodically checks the tty's
> statistics and when it changed since the last check the led is flashed
> once.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
> 
> On Wed, Jan 13, 2021 at 05:16:00PM +0100, Greg Kroah-Hartman wrote:
> > This causes the following build warning with the patch applied:
> > 
> > drivers/leds/trigger/ledtrig-tty.c:19:13: warning: ‘ledtrig_tty_halt’ defined but not used [-Wunused-function]
> >    19 | static void ledtrig_tty_halt(struct ledtrig_tty_data *trigger_data)
> >       |             ^~~~~~~~~~~~~~~~
> > 
> > Can you fix this up and just resend this patch (the other 2 are already
> > in my tree),
> 
> oh indeed. Thanks for catching this and so preventing me still more
> shame when I have to receive a dozen or so patches that fix this :-)
> Droping this function is the only change since v10.
> 
> > so that I can queue it up?
> 
> Oh, so you are LED maintainer now? My congratulations.
> (Honestly, do you plan to apply this without their ack? Not that I'm
> against you doing that, I'm happy if I can archive this patch series as
> done, but I'm a bit surprised.)

It's drug on for so long now, the infrastructure that this driver needs
has now bee merged, so I see no reason why this driver can't be taken
now.  I offered up a "any objections?" in the past, and have gotten
none, so I will take that for quiet acceptance :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v11] leds: trigger: implement a tty trigger
  2021-01-13 18:34       ` Greg Kroah-Hartman
@ 2021-02-18 13:33         ` Pavel Machek
  2021-02-18 21:19           ` Uwe Kleine-König
  0 siblings, 1 reply; 13+ messages in thread
From: Pavel Machek @ 2021-02-18 13:33 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Uwe Kleine-König, linux-kernel, Johan Hovold,
	Jacek Anaszewski, linux-serial, Jiri Slaby, kernel, linux-leds,
	Dan Murphy

[-- Attachment #1: Type: text/plain, Size: 779 bytes --]

Hi!

> > > so that I can queue it up?
> > 
> > Oh, so you are LED maintainer now? My congratulations.
> > (Honestly, do you plan to apply this without their ack? Not that I'm
> > against you doing that, I'm happy if I can archive this patch series as
> > done, but I'm a bit surprised.)
> 
> It's drug on for so long now, the infrastructure that this driver needs
> has now bee merged, so I see no reason why this driver can't be taken
> now.  I offered up a "any objections?" in the past, and have gotten
> none, so I will take that for quiet acceptance :)

Thanks for taking the infrastructure patches, but please drop this
one. Its buggy, as were previous versions. I'll handle it.

Best regards,
								Pavel
-- 
http://www.livejournal.com/~pavelmachek

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v11] leds: trigger: implement a tty trigger
  2021-01-13 17:30     ` [PATCH v11] " Uwe Kleine-König
  2021-01-13 18:34       ` Greg Kroah-Hartman
@ 2021-02-18 13:37       ` Pavel Machek
  2021-02-19  8:00         ` Uwe Kleine-König
  1 sibling, 1 reply; 13+ messages in thread
From: Pavel Machek @ 2021-02-18 13:37 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Greg Kroah-Hartman, linux-kernel, Johan Hovold, Jacek Anaszewski,
	linux-serial, Jiri Slaby, kernel, linux-leds, Dan Murphy

[-- Attachment #1: Type: text/plain, Size: 1128 bytes --]

Hi!

Close, but see below:

> +static ssize_t ttyname_store(struct device *dev,
> +			     struct device_attribute *attr, const char *buf,
> +			     size_t size)
> +{
> +	struct ledtrig_tty_data *trigger_data = led_trigger_get_drvdata(dev);
> +	char *ttyname;
> +	ssize_t ret = size;
> +	bool running;
> +
> +	if (size > 0 && buf[size - 1] == '\n')
> +		size -= 1;
> +
> +	if (size) {
> +		ttyname = kmemdup_nul(buf, size, GFP_KERNEL);
> +		if (!ttyname) {
> +			ret = -ENOMEM;
> +			goto out_unlock;

Unlock without a lock:

> +out_unlock:
> +	mutex_unlock(&trigger_data->mutex);
> +
> +	if (ttyname && !running)
> +		ledtrig_tty_restart(trigger_data);
> +
> +	return ret;
> +}

> +
> +		tty = tty_kopen_shared(devno);
> +		if (IS_ERR(tty) || !tty)
> +			/* What to do? retry or abort */
> +			goto out;

Abort would make sense to me.

> +	if (icount.rx != trigger_data->rx ||
> +	    icount.tx != trigger_data->tx) {
> +		led_set_brightness(trigger_data->led_cdev, LED_ON);

Please use _sync version.

Best regards,
								Pavel
-- 
http://www.livejournal.com/~pavelmachek

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v11] leds: trigger: implement a tty trigger
  2021-02-18 13:33         ` Pavel Machek
@ 2021-02-18 21:19           ` Uwe Kleine-König
  2021-02-18 21:21             ` Greg Kroah-Hartman
  0 siblings, 1 reply; 13+ messages in thread
From: Uwe Kleine-König @ 2021-02-18 21:19 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Greg Kroah-Hartman, kernel, Johan Hovold, linux-kernel,
	Jacek Anaszewski, linux-serial, Jiri Slaby, linux-leds,
	Dan Murphy

[-- Attachment #1: Type: text/plain, Size: 1232 bytes --]

Hello Pavel,

On Thu, Feb 18, 2021 at 02:33:52PM +0100, Pavel Machek wrote:
> > > > so that I can queue it up?
> > > 
> > > Oh, so you are LED maintainer now? My congratulations.
> > > (Honestly, do you plan to apply this without their ack? Not that I'm
> > > against you doing that, I'm happy if I can archive this patch series as
> > > done, but I'm a bit surprised.)
> > 
> > It's drug on for so long now, the infrastructure that this driver needs
> > has now bee merged, so I see no reason why this driver can't be taken
> > now.  I offered up a "any objections?" in the past, and have gotten
> > none, so I will take that for quiet acceptance :)
> 
> Thanks for taking the infrastructure patches, but please drop this
> one.

Given it is already part of Greg's pull request I wonder if we need an
incremental patch instead?

> Its buggy, as were previous versions. I'll handle it.

*sigh*, you're right. I will prepare a fixed version tomorrow.
Maybe I know until then if I have to prepare a v12 or an incremental
patch.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v11] leds: trigger: implement a tty trigger
  2021-02-18 21:19           ` Uwe Kleine-König
@ 2021-02-18 21:21             ` Greg Kroah-Hartman
  0 siblings, 0 replies; 13+ messages in thread
From: Greg Kroah-Hartman @ 2021-02-18 21:21 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Pavel Machek, kernel, Johan Hovold, linux-kernel,
	Jacek Anaszewski, linux-serial, Jiri Slaby, linux-leds,
	Dan Murphy

On Thu, Feb 18, 2021 at 10:19:48PM +0100, Uwe Kleine-König wrote:
> Hello Pavel,
> 
> On Thu, Feb 18, 2021 at 02:33:52PM +0100, Pavel Machek wrote:
> > > > > so that I can queue it up?
> > > > 
> > > > Oh, so you are LED maintainer now? My congratulations.
> > > > (Honestly, do you plan to apply this without their ack? Not that I'm
> > > > against you doing that, I'm happy if I can archive this patch series as
> > > > done, but I'm a bit surprised.)
> > > 
> > > It's drug on for so long now, the infrastructure that this driver needs
> > > has now bee merged, so I see no reason why this driver can't be taken
> > > now.  I offered up a "any objections?" in the past, and have gotten
> > > none, so I will take that for quiet acceptance :)
> > 
> > Thanks for taking the infrastructure patches, but please drop this
> > one.
> 
> Given it is already part of Greg's pull request I wonder if we need an
> incremental patch instead?

An incremental patch is easier, thanks, I can't "drop" a patch already
in my public tree.

greg k-h

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v11] leds: trigger: implement a tty trigger
  2021-02-18 13:37       ` Pavel Machek
@ 2021-02-19  8:00         ` Uwe Kleine-König
  0 siblings, 0 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2021-02-19  8:00 UTC (permalink / raw)
  To: Pavel Machek
  Cc: kernel, Greg Kroah-Hartman, linux-kernel, Johan Hovold,
	Jacek Anaszewski, linux-serial, Jiri Slaby, linux-leds,
	Dan Murphy

[-- Attachment #1: Type: text/plain, Size: 2040 bytes --]

Hi Pavel,

On Thu, Feb 18, 2021 at 02:37:33PM +0100, Pavel Machek wrote:
> Close, but see below:
> 
> > +static ssize_t ttyname_store(struct device *dev,
> > +			     struct device_attribute *attr, const char *buf,
> > +			     size_t size)
> > +{
> > +	struct ledtrig_tty_data *trigger_data = led_trigger_get_drvdata(dev);
> > +	char *ttyname;
> > +	ssize_t ret = size;
> > +	bool running;
> > +
> > +	if (size > 0 && buf[size - 1] == '\n')
> > +		size -= 1;
> > +
> > +	if (size) {
> > +		ttyname = kmemdup_nul(buf, size, GFP_KERNEL);
> > +		if (!ttyname) {
> > +			ret = -ENOMEM;
> > +			goto out_unlock;
> 
> Unlock without a lock:
> 
> > +out_unlock:
> > +	mutex_unlock(&trigger_data->mutex);

Indeed, I prepare an incremental patch that does return -ENOMEM instead
of goto out_unlock.

> > +
> > +	if (ttyname && !running)
> > +		ledtrig_tty_restart(trigger_data);
> > +
> > +	return ret;
> > +}
> 
> > +
> > +		tty = tty_kopen_shared(devno);
> > +		if (IS_ERR(tty) || !tty)
> > +			/* What to do? retry or abort */
> > +			goto out;
> 
> Abort would make sense to me.

In this case it would IMHO be sensible to already try the
tty_kopen_shared() in ttyname_store() and let that one fail if the tty
doesn't exist. I'll have to go through the history of this patch set, if
I remember correctly it was like that at one point.

> > +	if (icount.rx != trigger_data->rx ||
> > +	    icount.tx != trigger_data->tx) {
> > +		led_set_brightness(trigger_data->led_cdev, LED_ON);
> 
> Please use _sync version.

OK, there are too many variants for me. I'll just believe you that
led_set_brightness_sync is the right one. (Hmm, on the other hand I'll
have to understand the difference for a good commit log. I'll dig into
that. "Pavel said so" probably isn't good enough :-))

Best regards and thanks for your review,
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-02-19  8:01 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-18 10:42 [PATCH v10 0/3] leds: trigger: implement a tty trigger Uwe Kleine-König
2020-12-18 10:42 ` [PATCH v10 1/3] tty: rename tty_kopen() and add new function tty_kopen_shared() Uwe Kleine-König
2020-12-18 10:42 ` [PATCH v10 2/3] tty: new helper function tty_get_icount() Uwe Kleine-König
2020-12-18 10:42 ` [PATCH v10 3/3] leds: trigger: implement a tty trigger Uwe Kleine-König
2021-01-13 16:16   ` Greg Kroah-Hartman
2021-01-13 17:30     ` [PATCH v11] " Uwe Kleine-König
2021-01-13 18:34       ` Greg Kroah-Hartman
2021-02-18 13:33         ` Pavel Machek
2021-02-18 21:19           ` Uwe Kleine-König
2021-02-18 21:21             ` Greg Kroah-Hartman
2021-02-18 13:37       ` Pavel Machek
2021-02-19  8:00         ` Uwe Kleine-König
2020-12-28 15:10 ` [PATCH v10 0/3] " Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.