linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Florian Eckert <fe@dev.tdt.de>
Cc: Eckert.Florian@googlemail.com, jirislaby@kernel.org,
	pavel@ucw.cz, lee@kernel.org, kabel@kernel.org,
	u.kleine-koenig@pengutronix.de, ansuelsmth@gmail.com,
	m.brock@vanmierlo.com, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org, linux-leds@vger.kernel.org
Subject: Re: [PATCH v4 3/3] leds: ledtrig-tty: add new line mode evaluation
Date: Sun, 22 Oct 2023 13:24:40 +0200	[thread overview]
Message-ID: <2023102235-wafer-plethora-ac3c@gregkh> (raw)
In-Reply-To: <72be6923ff6dd03a5d02d04ee1c5796f@dev.tdt.de>

On Sun, Oct 22, 2023 at 12:24:27PM +0200, Florian Eckert wrote:
> On 2023-10-21 18:07, Greg KH wrote:
> > > diff --git a/drivers/leds/trigger/ledtrig-tty.c
> > > b/drivers/leds/trigger/ledtrig-tty.c
> > > index 8ae0d2d284af..6a96439a7e55 100644
> > > --- a/drivers/leds/trigger/ledtrig-tty.c
> > > +++ b/drivers/leds/trigger/ledtrig-tty.c
> > > @@ -16,6 +16,24 @@ struct ledtrig_tty_data {
> > >  	const char *ttyname;
> > >  	struct tty_struct *tty;
> > >  	int rx, tx;
> > > +	unsigned long mode;
> > 
> > Why is mode "unsigned long" when the tty layer treats it as an int?  And
> > really, this should be set to an explit size, u32 perhaps?  Or am I
> > confused as to exactly what this is?
> 
> This is about the line state that the LED should show "altogether".
> All states that the LED is to display are stored here.
> 
> For example:
> Via the sysfs of the LED I can set the flags rx, tx and line_cts to
> a "not" zero value. That means that the led is enable if the CTS of the
> tty ist set, and the LED flashes if rx/tx data are transmitted via
> this tty.
> 
> Therefore, the bits 0 (TRIGGER_TTY_RX), 1 (TRIGGER_TTY_TX) and
> 2 (TRIGGER_TTY_CTS) are set in the variable. As defined in the
> enum led_trigger_tty_modes

So the enum is a bitfield value?  That's not obvious either, a comment
for the enum might be good to help describe that.

> I think I have not chosen the correct name for the variable there.
> Maybe line_state, would be a better choice?

Or "trigger_modes"?  "mode" feels odd, these are values, so maybe just
"triggers"?

Naming is hard :(

> > > +};
> > > +
> > > +enum led_trigger_tty_state {
> > > +	TTY_LED_BLINK,
> > > +	TTY_LED_ENABLE,
> > > +	TTY_LED_DISABLE,
> > > +};
> > > +
> > > +enum led_trigger_tty_modes {
> > > +	TRIGGER_TTY_RX = 0,
> > > +	TRIGGER_TTY_TX,
> > > +	TRIGGER_TTY_CTS,
> > > +	TRIGGER_TTY_DSR,
> > > +	TRIGGER_TTY_CAR,
> > > +	TRIGGER_TTY_RNG,
> > > +	/* Keep last */
> > > +	__TRIGGER_TTY_MAX,
> > >  };
> > > 
> > 
> > Oh wait, is "mode" this?  If so, why not define it as an enum?  Or if
> > not, I'm totally confused as to what is going on here, sorry.
> 
> See explanation above. I can not set this to an enum because I could
> set more then one Flag via the sysfs.

Ah, then say they are bits, enums are usually not used for that, or if
they are, they are documented better :)

> > >  static void ledtrig_tty_restart(struct ledtrig_tty_data
> > > *trigger_data)
> > > @@ -78,13 +96,106 @@ static ssize_t ttyname_store(struct device *dev,
> > >  }
> > >  static DEVICE_ATTR_RW(ttyname);
> > > 
> > > +static ssize_t ledtrig_tty_attr_show(struct device *dev, char *buf,
> > > +	enum led_trigger_tty_modes attr)
> > > +{
> > > +	struct ledtrig_tty_data *trigger_data =
> > > led_trigger_get_drvdata(dev);
> > > +	int bit;
> > > +
> > > +	switch (attr) {
> > > +	case TRIGGER_TTY_RX:
> > > +	case TRIGGER_TTY_TX:
> > > +	case TRIGGER_TTY_CTS:
> > > +	case TRIGGER_TTY_DSR:
> > > +	case TRIGGER_TTY_CAR:
> > > +	case TRIGGER_TTY_RNG:
> > > +		bit = attr;
> > > +		break;
> > > +	default:
> > > +		return -EINVAL;
> > > +	}
> > > +
> > > +	return sprintf(buf, "%u\n", test_bit(bit, &trigger_data->mode));
> > 
> > sysfs_emit() for all new sysfs attributes please.
> 
> Correct. Thanks for the hint will use sysf_emit() function in the next
> patchset round.
> 
> > 
> > > +}
> > > +
> > > +static ssize_t ledtrig_tty_attr_store(struct device *dev, const
> > > char *buf,
> > > +	size_t size, enum led_trigger_tty_modes attr)
> > > +{
> > > +	struct ledtrig_tty_data *trigger_data =
> > > led_trigger_get_drvdata(dev);
> > > +	unsigned long state;
> > > +	int ret;
> > > +	int bit;
> > > +
> > > +	ret = kstrtoul(buf, 0, &state);
> > > +	if (ret)
> > > +		return ret;
> > > +
> > > +	switch (attr) {
> > > +	case TRIGGER_TTY_RX:
> > > +	case TRIGGER_TTY_TX:
> > > +	case TRIGGER_TTY_CTS:
> > > +	case TRIGGER_TTY_DSR:
> > > +	case TRIGGER_TTY_CAR:
> > > +	case TRIGGER_TTY_RNG:
> > > +		bit = attr;
> > > +		break;
> > > +	default:
> > > +		return -EINVAL;
> > > +	}
> > > +
> > > +	if (state)
> > > +		set_bit(bit, &trigger_data->mode);
> > > +	else
> > > +		clear_bit(bit, &trigger_data->mode);
> > 
> > I think your test of "state" here is wrong, if you write in "40000" you
> > are treating it as "1", which I don't think you want, right?
> 
> If I have understood your question correctly, then I would say that your
> assumption is not correct. I just want to check here whether it is a number
> greater than zero or not. If the number is greater than zero then the bit
> should be set in the 'mode' variable of the struct and if it is zero then
> it should be cleared.

"greater than 0" can be any number, that's not a good api.  Use the
sysfs api that can handle a boolean, it will deal with "y/N" and 0/1 and
all sorts of other options that way for you automatically.

> The LED could indicate more then one state there. As described above.
> This was requested by Uwe Kleine-König in the old v7 patch series [1].

That's fine, but you need to fix up the userspace api a bit here.

thanks,

greg k-h

      reply	other threads:[~2023-10-22 11:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-19 11:28 [PATCH v4 0/3] ledtrig-tty: add additional tty state evaluation Florian Eckert
2023-10-19 11:28 ` [PATCH v4 1/3] tty: whitespaces in descriptions corrected by replacing tabs with spaces Florian Eckert
2023-10-21 16:08   ` Greg KH
2023-10-21 16:28   ` Greg KH
2023-10-22 10:24     ` Florian Eckert
2023-10-22 11:19       ` Greg KH
2023-10-19 11:28 ` [PATCH v4 2/3] tty: add new helper function tty_get_tiocm Florian Eckert
2023-10-21 16:15   ` Greg KH
2023-10-22 10:24     ` Florian Eckert
2023-10-19 11:28 ` [PATCH v4 3/3] leds: ledtrig-tty: add new line mode evaluation Florian Eckert
2023-10-21 16:07   ` Greg KH
2023-10-22 10:24     ` Florian Eckert
2023-10-22 11:24       ` Greg KH [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2023102235-wafer-plethora-ac3c@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=Eckert.Florian@googlemail.com \
    --cc=ansuelsmth@gmail.com \
    --cc=fe@dev.tdt.de \
    --cc=jirislaby@kernel.org \
    --cc=kabel@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=m.brock@vanmierlo.com \
    --cc=pavel@ucw.cz \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).