LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: sim: quietly ignore configured lines outside the bank
@ 2023-06-07  6:50 Kent Gibson
  2023-06-07 12:50 ` Bartosz Golaszewski
  0 siblings, 1 reply; 4+ messages in thread
From: Kent Gibson @ 2023-06-07  6:50 UTC (permalink / raw
  To: linux-kernel, linux-gpio, brgl, linus.walleij; +Cc: Kent Gibson

The user-space policy of the gpio-sim is that configuration for lines
with offsets outside the bounds of the corresponding bank is ignored,
but gpio-sim is still using that configuration when constructing the
sim.  In the case of named lines this results in temporarily allocating
space for names that are not used, and for hogs results in errors being
logged when the gpio-sim attempts to register the out of range hog with
gpiolib:

gpiochip_machine_hog: unable to get GPIO desc: -22

Add checks to filter out any line configuration outside the bounds
of the bank when constructing the sim.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
---

This is based on for-next patched with my recent memory corruption fix,
as it touches a bit of the same code.

Cheers,
Kent.

 drivers/gpio/gpio-sim.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index fab67a5785d7..8b49b0abacd5 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -696,6 +696,9 @@ static char **gpio_sim_make_line_names(struct gpio_sim_bank *bank,
 	char **line_names;
 
 	list_for_each_entry(line, &bank->line_list, siblings) {
+		if (line->offset >= bank->num_lines)
+			continue;
+
 		if (line->name) {
 			if (line->offset > max_offset)
 				max_offset = line->offset;
@@ -722,6 +725,9 @@ static char **gpio_sim_make_line_names(struct gpio_sim_bank *bank,
 		return ERR_PTR(-ENOMEM);
 
 	list_for_each_entry(line, &bank->line_list, siblings) {
+		if (line->offset >= bank->num_lines)
+			continue;
+
 		if (line->name && (line->offset <= max_offset))
 			line_names[line->offset] = line->name;
 	}
@@ -756,6 +762,9 @@ static int gpio_sim_add_hogs(struct gpio_sim_device *dev)
 
 	list_for_each_entry(bank, &dev->bank_list, siblings) {
 		list_for_each_entry(line, &bank->line_list, siblings) {
+			if (line->offset >= bank->num_lines)
+				continue;
+
 			if (line->hog)
 				num_hogs++;
 		}
@@ -771,6 +780,9 @@ static int gpio_sim_add_hogs(struct gpio_sim_device *dev)
 
 	list_for_each_entry(bank, &dev->bank_list, siblings) {
 		list_for_each_entry(line, &bank->line_list, siblings) {
+			if (line->offset >= bank->num_lines)
+				continue;
+
 			if (!line->hog)
 				continue;
 

base-commit: ba65c79fbb813423e7d42d99375e2045b27958a6
prerequisite-patch-id: d89da2e3b7511c5b8132a379b12e4996256ac214
-- 
2.40.1


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

* Re: [PATCH] gpio: sim: quietly ignore configured lines outside the bank
  2023-06-07  6:50 [PATCH] gpio: sim: quietly ignore configured lines outside the bank Kent Gibson
@ 2023-06-07 12:50 ` Bartosz Golaszewski
  2023-06-07 12:54   ` Kent Gibson
  0 siblings, 1 reply; 4+ messages in thread
From: Bartosz Golaszewski @ 2023-06-07 12:50 UTC (permalink / raw
  To: Kent Gibson; +Cc: linux-kernel, linux-gpio, linus.walleij

On Wed, Jun 7, 2023 at 8:50 AM Kent Gibson <warthog618@gmail.com> wrote:
>
> The user-space policy of the gpio-sim is that configuration for lines
> with offsets outside the bounds of the corresponding bank is ignored,
> but gpio-sim is still using that configuration when constructing the
> sim.  In the case of named lines this results in temporarily allocating
> space for names that are not used, and for hogs results in errors being
> logged when the gpio-sim attempts to register the out of range hog with
> gpiolib:
>
> gpiochip_machine_hog: unable to get GPIO desc: -22
>
> Add checks to filter out any line configuration outside the bounds
> of the bank when constructing the sim.
>
> Signed-off-by: Kent Gibson <warthog618@gmail.com>
> ---
>
> This is based on for-next patched with my recent memory corruption fix,
> as it touches a bit of the same code.
>
> Cheers,
> Kent.
>
>  drivers/gpio/gpio-sim.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
> index fab67a5785d7..8b49b0abacd5 100644
> --- a/drivers/gpio/gpio-sim.c
> +++ b/drivers/gpio/gpio-sim.c
> @@ -696,6 +696,9 @@ static char **gpio_sim_make_line_names(struct gpio_sim_bank *bank,
>         char **line_names;
>
>         list_for_each_entry(line, &bank->line_list, siblings) {
> +               if (line->offset >= bank->num_lines)
> +                       continue;
> +
>                 if (line->name) {
>                         if (line->offset > max_offset)
>                                 max_offset = line->offset;
> @@ -722,6 +725,9 @@ static char **gpio_sim_make_line_names(struct gpio_sim_bank *bank,
>                 return ERR_PTR(-ENOMEM);
>
>         list_for_each_entry(line, &bank->line_list, siblings) {
> +               if (line->offset >= bank->num_lines)
> +                       continue;
> +
>                 if (line->name && (line->offset <= max_offset))
>                         line_names[line->offset] = line->name;
>         }
> @@ -756,6 +762,9 @@ static int gpio_sim_add_hogs(struct gpio_sim_device *dev)
>
>         list_for_each_entry(bank, &dev->bank_list, siblings) {
>                 list_for_each_entry(line, &bank->line_list, siblings) {
> +                       if (line->offset >= bank->num_lines)
> +                               continue;
> +
>                         if (line->hog)
>                                 num_hogs++;
>                 }
> @@ -771,6 +780,9 @@ static int gpio_sim_add_hogs(struct gpio_sim_device *dev)
>
>         list_for_each_entry(bank, &dev->bank_list, siblings) {
>                 list_for_each_entry(line, &bank->line_list, siblings) {
> +                       if (line->offset >= bank->num_lines)
> +                               continue;
> +
>                         if (!line->hog)
>                                 continue;
>
>
> base-commit: ba65c79fbb813423e7d42d99375e2045b27958a6
> prerequisite-patch-id: d89da2e3b7511c5b8132a379b12e4996256ac214
> --
> 2.40.1
>

I queued this for fixes, thanks!

Bart

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

* Re: [PATCH] gpio: sim: quietly ignore configured lines outside the bank
  2023-06-07 12:50 ` Bartosz Golaszewski
@ 2023-06-07 12:54   ` Kent Gibson
  2023-06-07 13:35     ` Bartosz Golaszewski
  0 siblings, 1 reply; 4+ messages in thread
From: Kent Gibson @ 2023-06-07 12:54 UTC (permalink / raw
  To: Bartosz Golaszewski; +Cc: linux-kernel, linux-gpio, linus.walleij

On Wed, Jun 07, 2023 at 02:50:43PM +0200, Bartosz Golaszewski wrote:
> On Wed, Jun 7, 2023 at 8:50 AM Kent Gibson <warthog618@gmail.com> wrote:
> >
> >
> > base-commit: ba65c79fbb813423e7d42d99375e2045b27958a6
> > prerequisite-patch-id: d89da2e3b7511c5b8132a379b12e4996256ac214
> > --
> > 2.40.1
> >
> 
> I queued this for fixes, thanks!
> 

Oh, ok.  I didn't think it was serious enough for fixes, or I would've
made the two patches a series.  And included a Fixes on this one.

Cheers,
Kent.

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

* Re: [PATCH] gpio: sim: quietly ignore configured lines outside the bank
  2023-06-07 12:54   ` Kent Gibson
@ 2023-06-07 13:35     ` Bartosz Golaszewski
  0 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2023-06-07 13:35 UTC (permalink / raw
  To: Kent Gibson; +Cc: linux-kernel, linux-gpio, linus.walleij

On Wed, Jun 7, 2023 at 2:54 PM Kent Gibson <warthog618@gmail.com> wrote:
>
> On Wed, Jun 07, 2023 at 02:50:43PM +0200, Bartosz Golaszewski wrote:
> > On Wed, Jun 7, 2023 at 8:50 AM Kent Gibson <warthog618@gmail.com> wrote:
> > >
> > >
> > > base-commit: ba65c79fbb813423e7d42d99375e2045b27958a6
> > > prerequisite-patch-id: d89da2e3b7511c5b8132a379b12e4996256ac214
> > > --
> > > 2.40.1
> > >
> >
> > I queued this for fixes, thanks!
> >
>
> Oh, ok.  I didn't think it was serious enough for fixes, or I would've
> made the two patches a series.  And included a Fixes on this one.
>
> Cheers,
> Kent.

It fixes a problem and is fairly small. Works as a fix for me.

Bart

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

end of thread, other threads:[~2023-06-07 13:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-07  6:50 [PATCH] gpio: sim: quietly ignore configured lines outside the bank Kent Gibson
2023-06-07 12:50 ` Bartosz Golaszewski
2023-06-07 12:54   ` Kent Gibson
2023-06-07 13:35     ` Bartosz Golaszewski

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 read-only IMAP folder(s) and NNTP newsgroup(s).