Skip to contentSkip to conversation

gpiolib: cdev: Split line_get_debounce_period() and use

PATCH In review Andy Shevchenko 5 participants 15 messages Dec 21, 2023 – Dec 28, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: cdev: Split line_get_debounce_period() and use

Instead of repeating the same code and reduce possible miss of READ_ONCE(), split line_get_debounce_period() heler out and use in the existing cases.

---
 drivers/gpio/gpiolib-cdev.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/gpio/gpiolib-cdev.c +14 -9
index 744734405912..c573820d5722 100644
@@ -651,6 +651,16 @@ static struct line *supinfo_find(struct gpio_desc *desc)
 	return NULL;
 }
 
+static unsigned int line_get_debounce_period(struct line *line)
+{
+	return READ_ONCE(line->debounce_period_us);
+}
+
+static inline bool line_has_supinfo(struct line *line)
+{
+	return line_get_debounce_period(line);
+}
+
 static void supinfo_to_lineinfo(struct gpio_desc *desc,
 				struct gpio_v2_line_info *info)
 {
@@ -665,15 +675,10 @@ static void supinfo_to_lineinfo(struct gpio_desc *desc,
 
 	attr = &info->attrs[info->num_attrs];
 	attr->id = GPIO_V2_LINE_ATTR_ID_DEBOUNCE;
-	attr->debounce_period_us = READ_ONCE(line->debounce_period_us);
+	attr->debounce_period_us = line_get_debounce_period(line);
 	info->num_attrs++;
 }
 
-static inline bool line_has_supinfo(struct line *line)
-{
-	return READ_ONCE(line->debounce_period_us);
-}
-
 /*
  * Checks line_has_supinfo() before and after the change to avoid unnecessary
  * supinfo_tree access.
@@ -846,7 +851,7 @@ static enum hte_return process_hw_ts(struct hte_ts_data *ts, void *p)
 		line->total_discard_seq++;
 		line->last_seqno = ts->seq;
 		mod_delayed_work(system_wq, &line->work,
-		  usecs_to_jiffies(READ_ONCE(line->debounce_period_us)));
+				 usecs_to_jiffies(line_get_debounce_period(line)));
 	} else {
 		if (unlikely(ts->seq < line->line_seqno))
 			return HTE_CB_HANDLED;
@@ -987,7 +992,7 @@ static irqreturn_t debounce_irq_handler(int irq, void *p)
 	struct line *line = p;
 
 	mod_delayed_work(system_wq, &line->work,
-		usecs_to_jiffies(READ_ONCE(line->debounce_period_us)));
+			 usecs_to_jiffies(line_get_debounce_period(line)));
 
 	return IRQ_HANDLED;
 }
@@ -1215,7 +1220,7 @@ static int edge_detector_update(struct line *line,
 			gpio_v2_line_config_debounce_period(lc, line_idx);
 
 	if ((active_edflags == edflags) &&
-	    (READ_ONCE(line->debounce_period_us) == debounce_period_us))
+	    (line_get_debounce_period(line) == debounce_period_us))
 		return 0;
 
 	/* sw debounced and still will be...*/
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
reviewer
#1 lore raw
Quoted 4 lines · Andy Shevchenko

Instead of repeating the same code and reduce possible miss of READ_ONCE(), split line_get_debounce_period() heler out and use in the existing cases.

helper

Not a fan of this change.

So using READ_ONCE() is repeating code??
Doesn't providing a wrapper around READ_ONCE() just rename that repitition? What of all the other uses of READ_ONCE() in cdev (and there are a lot) - why pick on debounce_period?

The line_set_debounce_period() is necessary as the set is now a multi-step process as it can impact whether the line is contained in the supinfo_tree. The get is just a get.

And you could've included me in the Cc so I didn't just find it by accident.

Cheers,
Kent.

Quoted 73 lines
---
 drivers/gpio/gpiolib-cdev.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/gpio/gpiolib-cdev.c +14 -10
index 744734405912..c573820d5722 100644
@@ -651,6 +651,16 @@ static struct line *supinfo_find(struct gpio_desc *desc)
 	return NULL;
 }
 
+static unsigned int line_get_debounce_period(struct line *line)
+{
+	return READ_ONCE(line->debounce_period_us);
+}
+
+static inline bool line_has_supinfo(struct line *line)
+{
+	return line_get_debounce_period(line);
+}
+
 static void supinfo_to_lineinfo(struct gpio_desc *desc,
 				struct gpio_v2_line_info *info)
 {
@@ -665,15 +675,10 @@ static void supinfo_to_lineinfo(struct gpio_desc *desc,
 
 	attr = &info->attrs[info->num_attrs];
 	attr->id = GPIO_V2_LINE_ATTR_ID_DEBOUNCE;
-	attr->debounce_period_us = READ_ONCE(line->debounce_period_us);
+	attr->debounce_period_us = line_get_debounce_period(line);
 	info->num_attrs++;
 }
 
-static inline bool line_has_supinfo(struct line *line)
-{
-	return READ_ONCE(line->debounce_period_us);
-}
-
 /*
  * Checks line_has_supinfo() before and after the change to avoid unnecessary
  * supinfo_tree access.
@@ -846,7 +851,7 @@ static enum hte_return process_hw_ts(struct hte_ts_data *ts, void *p)
 		line->total_discard_seq++;
 		line->last_seqno = ts->seq;
 		mod_delayed_work(system_wq, &line->work,
-		  usecs_to_jiffies(READ_ONCE(line->debounce_period_us)));
+				 usecs_to_jiffies(line_get_debounce_period(line)));
 	} else {
 		if (unlikely(ts->seq < line->line_seqno))
 			return HTE_CB_HANDLED;
@@ -987,7 +992,7 @@ static irqreturn_t debounce_irq_handler(int irq, void *p)
 	struct line *line = p;
 
 	mod_delayed_work(system_wq, &line->work,
-		usecs_to_jiffies(READ_ONCE(line->debounce_period_us)));
+			 usecs_to_jiffies(line_get_debounce_period(line)));
 
 	return IRQ_HANDLED;
 }
@@ -1215,7 +1220,7 @@ static int edge_detector_update(struct line *line,
 			gpio_v2_line_config_debounce_period(lc, line_idx);
 
 	if ((active_edflags == edflags) &&
-	    (READ_ONCE(line->debounce_period_us) == debounce_period_us))
+	    (line_get_debounce_period(line) == debounce_period_us))
 		return 0;
 
 	/* sw debounced and still will be...*/
--

2.43.0.rc1.1.gbec44491f096

#2 lore raw
Quoted 7 lines · Kent Gibson
Quoted 4 lines · Andy Shevchenko

Instead of repeating the same code and reduce possible miss of READ_ONCE(), split line_get_debounce_period() heler out and use in the existing cases.

Quoted 5 lines

helper

Not a fan of this change.

Yeah, sorry but NAK. READ_ONCE() is well known and tells you what the code does. Arbitrary line_get_debounce_period() makes me have to look it up.

Bart

Quoted 88 lines

So using READ_ONCE() is repeating code??
Doesn't providing a wrapper around READ_ONCE() just rename that repitition? What of all the other uses of READ_ONCE() in cdev (and there are a lot) - why pick on debounce_period?

The line_set_debounce_period() is necessary as the set is now a multi-step process as it can impact whether the line is contained in the supinfo_tree. The get is just a get.

And you could've included me in the Cc so I didn't just find it by accident.

Cheers,
Kent.

Quoted 73 lines
---
 drivers/gpio/gpiolib-cdev.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/gpio/gpiolib-cdev.c +14 -10
index 744734405912..c573820d5722 100644
@@ -651,6 +651,16 @@ static struct line *supinfo_find(struct gpio_desc *desc)
      return NULL;
 }
 
+static unsigned int line_get_debounce_period(struct line *line)
+{
+     return READ_ONCE(line->debounce_period_us);
+}
+
+static inline bool line_has_supinfo(struct line *line)
+{
+     return line_get_debounce_period(line);
+}
+
 static void supinfo_to_lineinfo(struct gpio_desc *desc,
                              struct gpio_v2_line_info *info)
 {
@@ -665,15 +675,10 @@ static void supinfo_to_lineinfo(struct gpio_desc *desc,
 
      attr = &info->attrs[info->num_attrs];
      attr->id = GPIO_V2_LINE_ATTR_ID_DEBOUNCE;
-     attr->debounce_period_us = READ_ONCE(line->debounce_period_us);
+     attr->debounce_period_us = line_get_debounce_period(line);
      info->num_attrs++;
 }
 
-static inline bool line_has_supinfo(struct line *line)
-{
-     return READ_ONCE(line->debounce_period_us);
-}
-
 /*
  * Checks line_has_supinfo() before and after the change to avoid unnecessary
  * supinfo_tree access.
@@ -846,7 +851,7 @@ static enum hte_return process_hw_ts(struct hte_ts_data *ts, void *p)
              line->total_discard_seq++;
              line->last_seqno = ts->seq;
              mod_delayed_work(system_wq, &line->work,
-               usecs_to_jiffies(READ_ONCE(line->debounce_period_us)));
+                              usecs_to_jiffies(line_get_debounce_period(line)));
      } else {
              if (unlikely(ts->seq < line->line_seqno))
                      return HTE_CB_HANDLED;
@@ -987,7 +992,7 @@ static irqreturn_t debounce_irq_handler(int irq, void *p)
      struct line *line = p;
 
      mod_delayed_work(system_wq, &line->work,
-             usecs_to_jiffies(READ_ONCE(line->debounce_period_us)));
+                      usecs_to_jiffies(line_get_debounce_period(line)));
 
      return IRQ_HANDLED;
 }
@@ -1215,7 +1220,7 @@ static int edge_detector_update(struct line *line,
                      gpio_v2_line_config_debounce_period(lc, line_idx);
 
      if ((active_edflags == edflags) &&
-         (READ_ONCE(line->debounce_period_us) == debounce_period_us))
+         (line_get_debounce_period(line) == debounce_period_us))
              return 0;
 
      /* sw debounced and still will be...*/
--

2.43.0.rc1.1.gbec44491f096

#3 lore raw
Quoted 11 lines · Bartosz Golaszewski
Quoted 10 lines · Kent Gibson
Quoted 4 lines · Andy Shevchenko

Instead of repeating the same code and reduce possible miss of READ_ONCE(), split line_get_debounce_period() heler out and use in the existing cases.

helper

Quoted 6 lines
Quoted 2 lines

Not a fan of this change.

Yeah, sorry but NAK. READ_ONCE() is well known and tells you what the code does. Arbitrary line_get_debounce_period() makes me have to look it up.

We have setter, but not getter. It looks confusing, more over, the setter makes much more than just set. Hence another way to solve this is make clear (by changing name) that the setter is not _just_ a setter.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
reviewer
#4 lore raw
Quoted 15 lines · Andy Shevchenko
Quoted 14 lines · Bartosz Golaszewski
Quoted 12 lines · Kent Gibson
Quoted 4 lines · Andy Shevchenko

Instead of repeating the same code and reduce possible miss of READ_ONCE(), split line_get_debounce_period() heler out and use in the existing cases.

helper

Not a fan of this change.

Quoted 8 lines
Quoted 3 lines

Yeah, sorry but NAK. READ_ONCE() is well known and tells you what the code does. Arbitrary line_get_debounce_period() makes me have to look it up.

We have setter, but not getter. It looks confusing, more over, the setter makes much more than just set. Hence another way to solve this is make clear (by changing name) that the setter is not _just_ a setter.

As I mentioned elsewhere, the side effects of the setter are irrelevant to the caller, so from their point of view it is _just_ a setter. Calling it something else would actually be more confusing.

Cheers,
Kent.

#5 lore raw
In reply to Kent Gibson
Quoted 11 lines · Kent Gibson
Quoted 4 lines · Andy Shevchenko

Instead of repeating the same code and reduce possible miss of READ_ONCE(), split line_get_debounce_period() heler out and use in the existing cases.

helper

Not a fan of this change.

So using READ_ONCE() is repeating code??

Yes. Because one may forget about it.

Quoted 3 lines

Doesn't providing a wrapper around READ_ONCE() just rename that repitition? What of all the other uses of READ_ONCE() in cdev (and there are a lot) - why pick on debounce_period?

Because you have a setter, but getter. Inconsistency.

Quoted 6 lines

The line_set_debounce_period() is necessary as the set is now a multi-step process as it can impact whether the line is contained in the supinfo_tree. The get is just a get.

And you could've included me in the Cc so I didn't just find it by accident.

Maybe it's time to add you to the MAINTAINERS for this file as a designated reviewer?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
reviewer
#6 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Kent Gibson
Quoted 4 lines · Andy Shevchenko

Instead of repeating the same code and reduce possible miss of READ_ONCE(), split line_get_debounce_period() heler out and use in the existing cases.

Quoted 7 lines
Quoted 5 lines

helper

Not a fan of this change.

So using READ_ONCE() is repeating code??

Yes. Because one may forget about it.

Just as one may forget to use your wrapper. This argument is a NULL - so I'll just forget about it.

Quoted 7 lines
Quoted 4 lines

Doesn't providing a wrapper around READ_ONCE() just rename that repitition? What of all the other uses of READ_ONCE() in cdev (and there are a lot) - why pick on debounce_period?

Because you have a setter, but getter. Inconsistency.

But then "for consistency" ALL the struct line fields require accessors and mutators. That path is insanity.

The setter is there as setting the value now has side effects - none of which are visible to the caller, hence the usage of the standard setter name.
You are siggesting every function name describe everything the function does?

And, in case you've forgotten, YOU REVIEWED THIS.

Quoted 10 lines
Quoted 6 lines

The line_set_debounce_period() is necessary as the set is now a multi-step process as it can impact whether the line is contained in the supinfo_tree. The get is just a get.

And you could've included me in the Cc so I didn't just find it by accident.

Maybe it's time to add you to the MAINTAINERS for this file as a designated reviewer?

You are patching my recent change that you yourself reviewed only days ago. I would think that you would Cc me whether I were a maintainer or not as I'm very likely to have relevant feedback.

Cheers,
Kent.

#7 lore raw
Quoted 46 lines · Kent Gibson
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Kent Gibson
Quoted 4 lines · Andy Shevchenko

Instead of repeating the same code and reduce possible miss of READ_ONCE(), split line_get_debounce_period() heler out and use in the existing cases.

Quoted 7 lines
Quoted 5 lines

helper

Not a fan of this change.

So using READ_ONCE() is repeating code??

Yes. Because one may forget about it.

Just as one may forget to use your wrapper. This argument is a NULL - so I'll just forget about it.

Quoted 7 lines
Quoted 4 lines

Doesn't providing a wrapper around READ_ONCE() just rename that repitition? What of all the other uses of READ_ONCE() in cdev (and there are a lot) - why pick on debounce_period?

Because you have a setter, but getter. Inconsistency.

But then "for consistency" ALL the struct line fields require accessors and mutators. That path is insanity.

The setter is there as setting the value now has side effects - none of which are visible to the caller, hence the usage of the standard setter name.
You are siggesting every function name describe everything the function does?

And, in case you've forgotten, YOU REVIEWED THIS.

Quoted 7 lines
Quoted 6 lines

The line_set_debounce_period() is necessary as the set is now a multi-step process as it can impact whether the line is contained in the supinfo_tree. The get is just a get.

And you could've included me in the Cc so I didn't just find it by accident.

Quoted 7 lines
Quoted 3 lines

Maybe it's time to add you to the MAINTAINERS for this file as a designated reviewer?

You are patching my recent change that you yourself reviewed only days ago. I would think that you would Cc me whether I were a maintainer or not as I'm very likely to have relevant feedback.

On that note: do you see yourself as a full GPIO reviewer or do you prefer I split out the uAPI part into a separate section in MAINTAINERS and nominate you as its maintainer?

Bart

Quoted 3 lines

Cheers,
Kent.

reviewer
#8 lore raw
Quoted 10 lines · Bartosz Golaszewski
Quoted 9 lines · Kent Gibson
Quoted 8 lines
Quoted 4 lines

And you could've included me in the Cc so I didn't just find it by accident.

Maybe it's time to add you to the MAINTAINERS for this file as a designated reviewer?

Quoted 8 lines
Quoted 3 lines

You are patching my recent change that you yourself reviewed only days ago. I would think that you would Cc me whether I were a maintainer or not as I'm very likely to have relevant feedback.

On that note: do you see yourself as a full GPIO reviewer or do you prefer I split out the uAPI part into a separate section in MAINTAINERS and nominate you as its maintainer?

Not sure I'm comfortable with either.

Definitely not full GPIO. I don't feel sufficiently familiar with GPIO and the related subsystems to qualify.

Splitting out cdev and the uAPI makes more sense to me, but in my mind at least even that requires a level of commitment higher than the rather spotty attention I've been providing recently.
I'm more inclined to leave it as is.

Cheers,
Kent.

#9 lore raw
Quoted 23 lines · Kent Gibson
Quoted 10 lines · Bartosz Golaszewski
Quoted 9 lines · Kent Gibson
Quoted 8 lines
Quoted 4 lines

And you could've included me in the Cc so I didn't just find it by accident.

Maybe it's time to add you to the MAINTAINERS for this file as a designated reviewer?

Quoted 8 lines
Quoted 3 lines

You are patching my recent change that you yourself reviewed only days ago. I would think that you would Cc me whether I were a maintainer or not as I'm very likely to have relevant feedback.

On that note: do you see yourself as a full GPIO reviewer or do you prefer I split out the uAPI part into a separate section in MAINTAINERS and nominate you as its maintainer?

Not sure I'm comfortable with either.

Quoted 8 lines

Definitely not full GPIO. I don't feel sufficiently familiar with GPIO and the related subsystems to qualify.

Splitting out cdev and the uAPI makes more sense to me, but in my mind at least even that requires a level of commitment higher than the rather spotty attention I've been providing recently.
I'm more inclined to leave it as is.

I can still split the uAPI files into their own section, make Linus and myself maintainers and make you a reviewer, how about that?

Bart

Quoted 2 lines

Cheers,
Kent.

reviewer
#10 lore raw
Quoted 27 lines · Bartosz Golaszewski
Quoted 26 lines · Kent Gibson
Quoted 10 lines · Bartosz Golaszewski
Quoted 9 lines · Kent Gibson
Quoted 8 lines
Quoted 4 lines

And you could've included me in the Cc so I didn't just find it by accident.

Maybe it's time to add you to the MAINTAINERS for this file as a designated reviewer?

Quoted 8 lines
Quoted 3 lines

You are patching my recent change that you yourself reviewed only days ago. I would think that you would Cc me whether I were a maintainer or not as I'm very likely to have relevant feedback.

On that note: do you see yourself as a full GPIO reviewer or do you prefer I split out the uAPI part into a separate section in MAINTAINERS and nominate you as its maintainer?

Not sure I'm comfortable with either.

Definitely not full GPIO. I don't feel sufficiently familiar with GPIO and the related subsystems to qualify.

Quoted 9 lines
Quoted 5 lines

Splitting out cdev and the uAPI makes more sense to me, but in my mind at least even that requires a level of commitment higher than the rather spotty attention I've been providing recently.
I'm more inclined to leave it as is.

I can still split the uAPI files into their own section, make Linus and myself maintainers and make you a reviewer, how about that?

That is closer to the reality, so that would work for me.

Cheers,
Kent.

#11 lore raw
Quoted 6 lines · Kent Gibson
Quoted 2 lines · Bartosz Golaszewski

I can still split the uAPI files into their own section, make Linus and myself maintainers and make you a reviewer, how about that?

That is closer to the reality, so that would work for me.

Hmm I think of Kent as one of the main architects for UAPI v2 so I would like you as maintainer, and me to be dropped, I already responded to that patch though.

Yours,
Linus Walleij

reviewer
#12 lore raw
Quoted 12 lines · Linus Walleij
Quoted 6 lines · Kent Gibson
Quoted 2 lines · Bartosz Golaszewski

I can still split the uAPI files into their own section, make Linus and myself maintainers and make you a reviewer, how about that?

That is closer to the reality, so that would work for me.

Hmm I think of Kent as one of the main architects for UAPI v2 so I would like you as maintainer, and me to be dropped, I already responded to that patch though.

There is no escaping that my fingerprints are all over that so it does make sense to list me over you. Given that patch and git-tree management will be deferred to the GPIO subsystem/Bart, there isn't much distinction between a reviewer and a maintainer, so I'm ok with being listed as a maintainer - I'll just have to pay a bit more attention to the list mails than I have been.

Cheers,
Kent.

#13 lore raw

Hi Kent,

Quoted 6 lines · Kent Gibson

There is no escaping that my fingerprints are all over that so it does make sense to list me over you. Given that patch and git-tree management will be deferred to the GPIO subsystem/Bart, there isn't much distinction between a reviewer and a maintainer, so I'm ok with being listed as a maintainer - I'll just have to pay a bit more attention to the list mails than I have been.

You're doing fine with responsiveness and feedback is always timely and verbose, so just keep doing what you do :)

Yours,
Linus Walleij

reviewer
#14 lore raw
Quoted 11 lines · Linus Walleij

Hi Kent,

Quoted 6 lines · Kent Gibson

There is no escaping that my fingerprints are all over that so it does make sense to list me over you. Given that patch and git-tree management will be deferred to the GPIO subsystem/Bart, there isn't much distinction between a reviewer and a maintainer, so I'm ok with being listed as a maintainer - I'll just have to pay a bit more attention to the list mails than I have been.

Quoted 3 lines

You're doing fine with responsiveness and feedback is always timely and verbose, so just keep doing what you do :)

I endeavour to reply to direct mail promptly, but I was thinking more of mail directed generally to the list and there have been times I haven't checked the list for months.

Cheers,
Kent.