gpio: mockup: updates for 4.13
Subsystems (2)
PATCH 2/10 gpio: mockup: add prefixes to the direction enum
In reply to Bartosz GolaszewskiAll internal symbols except for the direction enum follow the same convention and use the gpio_mockup prefix. Add the prefix to the DIR_IN and DIR_OUT definitions as well for consistency across the file.
--- drivers/gpio/gpio-mockup.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpio/gpio-mockup.c +4 -4
@@ -29,8 +29,8 @@#define GPIO_MOCKUP_MAX_GC 10enum { -DIR_OUT =0 , -DIR_IN =1 , +GPIO_MOCKUP_DIR_OUT =0 , +GPIO_MOCKUP_DIR_IN =1 , };/*
@@ -93,7 +93,7 @@ static int gpio_mockup_dirout(struct gpio_chip *gc, unsigned int offset,struct gpio_mockup_chip *chip =gpiochip_get_data (gc);gpio_mockup_set (gc, offset, value); - chip->lines[offset].dir =DIR_OUT ; + chip->lines[offset].dir =GPIO_MOCKUP_DIR_OUT ;return 0 ; }
@@ -102,7 +102,7 @@ static int gpio_mockup_dirin(struct gpio_chip *gc, unsigned int offset) {struct gpio_mockup_chip *chip =gpiochip_get_data (gc); - chip->lines[offset].dir =DIR_IN ; + chip->lines[offset].dir =GPIO_MOCKUP_DIR_IN ;return 0 ; }
Signature · 1 line
2.9.3
PATCH 7/10 gpio: mockup: improve readability
In reply to Bartosz GolaszewskiWe currently shift bits here and there without actually explaining what we're doing. Add some helper variables with names indicating their purpose to improve the code readability.
--- drivers/gpio/gpio-mockup.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/gpio/gpio-mockup.c +13 -7
@@ -27,6 +27,11 @@#define GPIO_MOCKUP_NAME "gpio-mockup"#define GPIO_MOCKUP_MAX_GC 10 +/* +* We're storing two values per chip: the GPIO base and the number +* of GPIO lines. +*/ +#define GPIO_MOCKUP_MAX_RANGES (GPIO_MOCKUP_MAX_GC * 2)enum {GPIO_MOCKUP_DIR_OUT =0 ,
@@ -62,7 +67,7 @@ struct gpio_mockup_dbgfs_private {int offset; }; -static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_GC <<1 ]; +static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_RANGES ];static int gpio_mockup_params_nr;module_param_array (gpio_mockup_ranges, int, &gpio_mockup_params_nr,0400 );
@@ -341,23 +346,24 @@ static int gpio_mockup_add(struct device *dev,static int gpio_mockup_probe (struct platform_device *pdev) { -struct gpio_mockup_chip *chips; +int ret, i, base, ngpio, num_chips;struct device *dev = &pdev->dev; -int ret, i, base, ngpio; +struct gpio_mockup_chip *chips;char *chip_name;if (gpio_mockup_params_nr <2 || (gpio_mockup_params_nr %2 ))return -EINVAL ; - chips =devm_kzalloc (dev, -sizeof (*chips) * (gpio_mockup_params_nr >>1 ), -GFP_KERNEL ); +/* Each chip is described by two values. */ + num_chips = gpio_mockup_params_nr /2 ; + + chips =devm_kzalloc (dev,sizeof (*chips) * num_chips,GFP_KERNEL );if (!chips)return -ENOMEM ;platform_set_drvdata (pdev, chips); -for (i =0 ; i < gpio_mockup_params_nr >>1 ; i++) { +for (i =0 ; i < num_chips; i++) { base = gpio_mockup_ranges[i *2 ];if (base ==-1 )
Signature · 1 line
2.9.3
PATCH 9/10 gpio: mockup: improve the error message
In reply to Bartosz GolaszewskiIndicate the error number and make the message a bit more elaborate.
--- drivers/gpio/gpio-mockup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpio/gpio-mockup.c +3 -2
@@ -385,8 +385,9 @@ static int gpio_mockup_probe(struct platform_device *pdev) }if (ret) { -dev_err (dev,"gpio<%d..%d> add failed\n" , - base, base <0 ? ngpio : base + ngpio); +dev_err (dev, +"adding gpiochip failed: %d (base: %d, ngpio: %d)\n" , + ret, base, base <0 ? ngpio : base + ngpio);return ret; }
Signature · 1 line
2.9.3
cover gpio: mockup: updates for 4.13
This series contains a couple bug fixes and other minor updates for the GPIO testing module.
Bartosz Golaszewski (10):
gpio: mockup: fix direction values
gpio: mockup: add prefixes to the direction enum
gpio: mockup: be quiet unless something goes wrong
gpio: mockup: support irqmask and irqunmask
gpio: mockup: improve the debugfs input sanitization
gpio: mockup: refuse to accept an odd number of GPIO ranges
gpio: mockup: improve readability
gpio: mockup: don't return magic numbers from probe()
gpio: mockup: improve the error message
gpio: mockup: add myself as author
drivers/gpio/gpio-mockup.c | 82 ++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 28 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/10 gpio: mockup: fix direction values
The comment in linux/gpio/driver.h says:
@get_direction: returns direction for signal "offset", 0=out, 1=in
We got those switched at some point. Fix the values.
--- drivers/gpio/gpio-mockup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpio-mockup.c +2 -2
@@ -29,8 +29,8 @@#define GPIO_MOCKUP_MAX_GC 10enum { -DIR_IN =0 , -DIR_OUT , +DIR_OUT =0 , +DIR_IN =1 , };/*
Signature · 1 line
2.9.3
PATCH 3/10 gpio: mockup: be quiet unless something goes wrong
In reply to Bartosz GolaszewskiWhen inserting and removing the module repeatedly (e.g. when running the libgpiod test-suite) the kernel log gets clobbered with messages reporting successful creation of dummy gpiochips.
Remove this message and only emit logs when something bad happens.
--- drivers/gpio/gpio-mockup.c | 3 --- 1 file changed, 3 deletions(-)
drivers/gpio/gpio-mockup.c +0 -3
@@ -364,9 +364,6 @@ static int gpio_mockup_probe(struct platform_device *pdev)return ret; } - -dev_info (dev,"gpio<%d..%d> add successful!" , - base, base + ngpio); }return 0 ;
Signature · 1 line
2.9.3
PATCH 4/10 gpio: mockup: support irqmask and irqunmask
In reply to Bartosz GolaszewskiEven though this is a testing module, be nice and actually implement these functions.
--- drivers/gpio/gpio-mockup.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
drivers/gpio/gpio-mockup.c +20 -6
@@ -41,6 +41,7 @@ enum {struct gpio_mockup_line_status {int dir;bool value; +bool irq_enabled; };struct gpio_mockup_irq_context {
@@ -142,12 +143,21 @@ static int gpio_mockup_to_irq(struct gpio_chip *chip, unsigned int offset)return chip->irq_base + offset; } -/* -* While we should generally support irqmask and irqunmask, this driver is -* for testing purposes only so we don't care. -*/ -static void gpio_mockup_irqmask (struct irq_data *d) { } -static void gpio_mockup_irqunmask (struct irq_data *d) { } +static void gpio_mockup_irqmask (struct irq_data *data) +{ +struct gpio_chip *gc =irq_data_get_irq_chip_data (data); +struct gpio_mockup_chip *chip =gpiochip_get_data (gc); + + chip->lines[data->irq - gc->irq_base].irq_enabled = false; +} + +static void gpio_mockup_irqunmask (struct irq_data *data) +{ +struct gpio_chip *gc =irq_data_get_irq_chip_data (data); +struct gpio_mockup_chip *chip =gpiochip_get_data (gc); + + chip->lines[data->irq - gc->irq_base].irq_enabled = true; +}static struct irq_chip gpio_mockup_irqchip = { .name =GPIO_MOCKUP_NAME ,
@@ -178,6 +188,7 @@ static int gpio_mockup_irqchip_setup(struct device *dev,for (i =0 ; i < gc->ngpio; i++) {irq_set_chip (irq_base + i, gc->irqchip); +irq_set_chip_data (irq_base + i, gc);irq_set_handler (irq_base + i, &handle_simple_irq);irq_modify_status (irq_base + i,IRQ_NOREQUEST |IRQ_NOAUTOEN ,IRQ_NOPROBE );
@@ -206,6 +217,9 @@ static ssize_t gpio_mockup_event_write(struct file *file, chip = priv->chip; gc = &chip->gc; +if (!chip->lines[priv->offset].irq_enabled) +return size; +if (copy_from_user (&buf, usr_buf,1 ))return -EFAULT ;
Signature · 1 line
2.9.3
PATCH 5/10 gpio: mockup: improve the debugfs input sanitization
In reply to Bartosz GolaszewskiWe're currently only checking the first character of the input to the debugfs event files, so a string like '0sdfdsf' is valid and indicates a falling edge event.
Be more strict and only allow '0', '1', '0\n' & '1\n'.
--- drivers/gpio/gpio-mockup.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/gpio/gpio-mockup.c +10 -4
@@ -208,8 +208,8 @@ static ssize_t gpio_mockup_event_write(struct file *file,struct seq_file *sfile;struct gpio_desc *desc;struct gpio_chip *gc; +char buf[2 ];int val; -char buf; sfile = file->private_data; priv = sfile->private;
@@ -220,12 +220,18 @@ static ssize_t gpio_mockup_event_write(struct file *file,if (!chip->lines[priv->offset].irq_enabled)return size; -if (copy_from_user (&buf, usr_buf,1 )) +if (size >2 ) +return -EINVAL ; + +if (copy_from_user (&buf, usr_buf,2 ))return -EFAULT ; -if (buf =='0' ) +if (size ==2 && buf[1 ] !='\n' ) +return -EINVAL ; + +if (buf[0 ] =='0' ) val =0 ; -else if (buf =='1' ) +else if (buf[0 ] =='1' ) val =1 ;else return -EINVAL ;
Signature · 1 line
2.9.3
PATCH 6/10 gpio: mockup: refuse to accept an odd number of GPIO ranges
In reply to Bartosz GolaszewskiCurrently we ignore the last odd range value, since each chip is described by two values. Be more strict and require the user to pass an even number of ranges.
--- drivers/gpio/gpio-mockup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-mockup.c +1 -1
@@ -346,7 +346,7 @@ static int gpio_mockup_probe(struct platform_device *pdev)int ret, i, base, ngpio;char *chip_name; -if (gpio_mockup_params_nr <2 ) +if (gpio_mockup_params_nr <2 || (gpio_mockup_params_nr %2 ))return -EINVAL ; chips = devm_kzalloc(dev,
Signature · 1 line
2.9.3
PATCH 8/10 gpio: mockup: don't return magic numbers from probe()
In reply to Bartosz GolaszewskiWhen the requested number of GPIO lines is 0, return -EINVAL, not -1 which is -EPERM.
--- drivers/gpio/gpio-mockup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-mockup.c +1 -1
@@ -381,7 +381,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) ret =gpio_mockup_add (dev, &chips[i], chip_name, base, ngpio); }else { - ret =-1 ; + ret = -EINVAL ; }if (ret) {
Signature · 1 line
2.9.3
PATCH 10/10 gpio: mockup: add myself as author
In reply to Bartosz GolaszewskiJust taking credit for the recent changes and new features. :)
--- drivers/gpio/gpio-mockup.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpio/gpio-mockup.c +2 -0
@@ -3,6 +3,7 @@* * Copyright (C) 2014 Kamlakant Patel <[email protected]> * Copyright (C) 2015-2016 Bamvor Jian Zhang <[email protected]> +* Copyright (C) 2017 Bartosz Golaszewski <[email protected]> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the
@@ -444,5 +445,6 @@ module_exit(mock_device_exit);MODULE_AUTHOR ("Kamlakant Patel <[email protected]>" );MODULE_AUTHOR ("Bamvor Jian Zhang <[email protected]>" ); +MODULE_AUTHOR ("Bartosz Golaszewski <[email protected]>" );MODULE_DESCRIPTION ("GPIO Testing driver" );MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.9.3
Re: [PATCH 01/10] gpio: mockup: fix direction values
In reply to Bartosz GolaszewskiQuoted 5 lines · Bartosz Golaszewski
The comment in
linux/gpio/driver.hsays:@get_direction: returns direction for signal "offset", 0=out, 1=in
We got those switched at some point. Fix the values.
Shouldn't it have a Fixes tag?
Quoted 24 lines
Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/gpio/gpio-mockup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpio/gpio-mockup.c +2
-3@@ -29,8 +29,8 @@#define GPIO_MOCKUP_MAX_GC 10enum { -DIR_IN =0 , -DIR_OUT , +DIR_OUT =0 , +DIR_IN =1 , };/* -- 2.9.3
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 05/10] gpio: mockup: improve the debugfs input sanitization
In reply to Bartosz GolaszewskiQuoted 5 lines · Bartosz Golaszewski
We're currently only checking the first character of the input to the debugfs event files, so a string like '0sdfdsf' is valid and indicates a falling edge event.
Be more strict and only allow '0', '1', '0\n' & '1\n'.
Why not to be so strict and use
kstrtobool_from_user();
instead?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 05/10] gpio: mockup: improve the debugfs input sanitization
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski
We're currently only checking the first character of the input to the debugfs event files, so a string like '0sdfdsf' is valid and indicates a falling edge event.
Quoted 7 lines
Quoted 1 line
Be more strict and only allow '0', '1', '0\n' & '1\n'.
Why not to be so strict and use
kstrtobool_from_user();instead?
Or if you still wish to be strict,
ret = kstrtou8_from_user();
if (ret)
return ret;
if (val > 1)
return -ERANGE;
or alike.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 06/10] gpio: mockup: refuse to accept an odd number of GPIO ranges
In reply to Bartosz Golaszewskidrivers/gpio/gpio-mockup.c static int gpio_mockup_probe(struct platform_device *pdev) · line 349
Quoted 6 lines · Bartosz Golaszewski
Currently we ignore the last odd range value, since each chip is described by two values. Be more strict and require the user to pass an even number of ranges.
drivers/gpio/gpio-mockup.c +1
-1-if (gpio_mockup_params_nr <2 ) +if (gpio_mockup_params_nr <2 || (gpio_mockup_params_nr %2 ))
if (((gpio_mockup_params_nr + 1) & ~3) < 3)
3 might have a suffix regarding to the type of variable.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 06/10] gpio: mockup: refuse to accept an odd number of GPIO ranges
Quoted 11 lines · Andy Shevchenko
drivers/gpio/gpio-mockup.c static int gpio_mockup_probe(struct platform_device *pdev) · line 349
Quoted 6 lines · Bartosz Golaszewski
Currently we ignore the last odd range value, since each chip is described by two values. Be more strict and require the user to pass an even number of ranges.
drivers/gpio/gpio-mockup.c +1
-1-if (gpio_mockup_params_nr <2 ) +if (gpio_mockup_params_nr <2 || (gpio_mockup_params_nr %2 ))if (((gpio_mockup_params_nr + 1) & ~3) < 3)3 might have a suffix regarding to the type of variable.
Oh, ignore that, sorry, for a noise.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 05/10] gpio: mockup: improve the debugfs input sanitization
In reply to Andy Shevchenko2017-05-27 18:47 GMT+02:00 Andy Shevchenko <[email protected]>:
Quoted 7 lines
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski
We're currently only checking the first character of the input to the debugfs event files, so a string like '0sdfdsf' is valid and indicates a falling edge event.
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Be more strict and only allow '0', '1', '0\n' & '1\n'.
Why not to be so strict and use
kstrtobool_from_user();instead?
Because it doesn't really make sense here - we're indicating a RISING or FALLING edge event. This doesn't really correspond well with boolean values IMO.
Quoted 9 lines
Or if you still wish to be strict,
ret =kstrtou8_from_user();
if (ret)
return ret;if (val > 1)
return-ERANGE;or alike.
This one looks good, I'll include it in v2.
Thanks,
Bartosz
Re: [PATCH 01/10] gpio: mockup: fix direction values
In reply to Bartosz GolaszewskiQuoted 7 lines · Bartosz Golaszewski
The comment in
linux/gpio/driver.hsays:@get_direction: returns direction for signal "offset", 0=out, 1=in
We got those switched at some point. Fix the values.
Signed-off-by Bartosz Golaszewski <[email protected]>
Patch applied.
Yours,
Linus Walleij
Re: [PATCH 02/10] gpio: mockup: add prefixes to the direction enum
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
All internal symbols except for the direction enum follow the same convention and use the
gpio_mockupprefix. Add the prefix to theDIR_INandDIR_OUTdefinitions as well for consistency across the file.Signed-off-by Bartosz Golaszewski <[email protected]>
Patch applied.
Yours,
Linus Walleij
Re: [PATCH 03/10] gpio: mockup: be quiet unless something goes wrong
In reply to Bartosz GolaszewskiQuoted 7 lines · Bartosz Golaszewski
When inserting and removing the module repeatedly (e.g. when running the libgpiod test-suite) the kernel log gets clobbered with messages reporting successful creation of dummy gpiochips.
Remove this message and only emit logs when something bad happens.
Signed-off-by Bartosz Golaszewski <[email protected]>
Patch applied.
Yours,
Linus Walleij
Re: [PATCH 04/10] gpio: mockup: support irqmask and irqunmask
In reply to Bartosz GolaszewskiQuoted 4 lines · Bartosz Golaszewski
Even though this is a testing module, be nice and actually implement these functions.
Signed-off-by Bartosz Golaszewski <[email protected]>
Patch applied.
Yours,
Linus Walleij
Re: [PATCH 05/10] gpio: mockup: improve the debugfs input sanitization
In reply to Bartosz GolaszewskiQuoted 7 lines · Bartosz Golaszewski
We're currently only checking the first character of the input to the debugfs event files, so a string like '0sdfdsf' is valid and indicates a falling edge event.
Be more strict and only allow '0', '1', '0\n' & '1\n'.
Signed-off-by Bartosz Golaszewski <[email protected]>
Since I applied patches 1-4 you only need to resend from this point when posting v2.
Yours,
Linus Walleij