diff mbox series

[v1,4/5] gpiolib: acpi: Reuse struct acpi_gpio_params in struct acpi_gpio_lookup

Message ID 20250402122301.1517463-5-andriy.shevchenko@linux.intel.com
State New
Headers show
Series gpiolib: acpi: Refactor to shrink the code by ~8% | expand

Commit Message

Andy Shevchenko April 2, 2025, 12:21 p.m. UTC
Some of the contents of struct acpi_gpio_lookup repeats what we have
in the struct acpi_gpio_params. Reuse the latter in the former.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib-acpi.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

Comments

Mika Westerberg April 3, 2025, 10:35 a.m. UTC | #1
On Wed, Apr 02, 2025 at 03:21:19PM +0300, Andy Shevchenko wrote:
> Some of the contents of struct acpi_gpio_lookup repeats what we have
> in the struct acpi_gpio_params. Reuse the latter in the former.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpio/gpiolib-acpi.c | 34 ++++++++++++++++++----------------
>  1 file changed, 18 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
> index afeb8d1c7102..750724601106 100644
> --- a/drivers/gpio/gpiolib-acpi.c
> +++ b/drivers/gpio/gpiolib-acpi.c
> @@ -744,9 +744,7 @@ static int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
>  
>  struct acpi_gpio_lookup {
>  	struct acpi_gpio_info info;
> -	int index;
> -	u16 pin_index;
> -	bool active_low;
> +	struct acpi_gpio_params par;

params is better name

>  	struct gpio_desc *desc;
>  	int n;
>  };
> @@ -754,6 +752,7 @@ struct acpi_gpio_lookup {
>  static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
>  {
>  	struct acpi_gpio_lookup *lookup = data;
> +	struct acpi_gpio_params *par = &lookup->par;

These are not changed I guess so can this be const?

Ditto everywhere.

>  
>  	if (ares->type != ACPI_RESOURCE_TYPE_GPIO)
>  		return 1;
> @@ -765,12 +764,12 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
>  		u16 pin_index;
>  
>  		if (lookup->info.quirks & ACPI_GPIO_QUIRK_ONLY_GPIOIO && gpioint)
> -			lookup->index++;
> +			par->crs_entry_index++;
>  
> -		if (lookup->n++ != lookup->index)
> +		if (lookup->n++ != par->crs_entry_index)
>  			return 1;
>  
> -		pin_index = lookup->pin_index;
> +		pin_index = par->line_index;
>  		if (pin_index >= agpio->pin_table_length)
>  			return 1;
>  
> @@ -796,7 +795,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
>  			lookup->info.polarity = agpio->polarity;
>  			lookup->info.triggering = agpio->triggering;
>  		} else {
> -			lookup->info.polarity = lookup->active_low;
> +			lookup->info.polarity = par->active_low;
>  		}
>  
>  		lookup->info.flags = acpi_gpio_to_gpiod_flags(agpio, lookup->info.polarity);
> @@ -834,7 +833,8 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, const char *p
>  				     struct acpi_gpio_lookup *lookup)
>  {
>  	struct fwnode_reference_args args;
> -	unsigned int index = lookup->index;
> +	struct acpi_gpio_params *par = &lookup->par;
> +	unsigned int index = par->crs_entry_index;
>  	unsigned int quirks = 0;
>  	int ret;
>  
> @@ -857,9 +857,9 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, const char *p
>  	if (args.nargs != 3)
>  		return -EPROTO;
>  
> -	lookup->index = args.args[0];
> -	lookup->pin_index = args.args[1];
> -	lookup->active_low = !!args.args[2];
> +	par->crs_entry_index = args.args[0];
> +	par->line_index = args.args[1];
> +	par->active_low = !!args.args[2];
>  
>  	lookup->info.adev = to_acpi_device_node(args.fwnode);
>  	lookup->info.quirks = quirks;
> @@ -897,10 +897,11 @@ static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
>  						 struct acpi_gpio_info *info)
>  {
>  	struct acpi_gpio_lookup lookup;
> +	struct acpi_gpio_params *par = &lookup.par;
>  	int ret;
>  
>  	memset(&lookup, 0, sizeof(lookup));
> -	lookup.index = index;
> +	par->crs_entry_index = index;
>  
>  	if (propname) {
>  		dev_dbg(&adev->dev, "GPIO: looking up %s\n", propname);
> @@ -909,9 +910,9 @@ static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
>  		if (ret)
>  			return ERR_PTR(ret);
>  
> -		dev_dbg(&adev->dev, "GPIO: _DSD returned %s %d %u %u\n",
> -			dev_name(&lookup.info.adev->dev), lookup.index,
> -			lookup.pin_index, lookup.active_low);
> +		dev_dbg(&adev->dev, "GPIO: _DSD returned %s %u %u %u\n",
> +			dev_name(&lookup.info.adev->dev),
> +			par->crs_entry_index, par->line_index, par->active_low);
>  	} else {
>  		dev_dbg(&adev->dev, "GPIO: looking up %d in _CRS\n", index);
>  		lookup.info.adev = adev;
> @@ -943,6 +944,7 @@ static struct gpio_desc *acpi_get_gpiod_from_data(struct fwnode_handle *fwnode,
>  						  struct acpi_gpio_info *info)
>  {
>  	struct acpi_gpio_lookup lookup;
> +	struct acpi_gpio_params *par = &lookup.par;
>  	int ret;
>  
>  	if (!is_acpi_data_node(fwnode))
> @@ -952,7 +954,7 @@ static struct gpio_desc *acpi_get_gpiod_from_data(struct fwnode_handle *fwnode,
>  		return ERR_PTR(-EINVAL);
>  
>  	memset(&lookup, 0, sizeof(lookup));
> -	lookup.index = index;
> +	par->crs_entry_index = index;
>  
>  	ret = acpi_gpio_property_lookup(fwnode, propname, &lookup);
>  	if (ret)
> -- 
> 2.47.2
Bartosz Golaszewski April 3, 2025, 11:57 a.m. UTC | #2
On Thu, Apr 3, 2025 at 1:04 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, Apr 03, 2025 at 01:35:06PM +0300, Mika Westerberg wrote:
> > On Wed, Apr 02, 2025 at 03:21:19PM +0300, Andy Shevchenko wrote:
> > > Some of the contents of struct acpi_gpio_lookup repeats what we have
> > > in the struct acpi_gpio_params. Reuse the latter in the former.
>
> > > +   struct acpi_gpio_params par;
> >
> > params is better name
>
> It's been already used elsewhere in the code. Do you want renaming there as
> well for consistency's sake?
>

+1 for using param or params here and elsewhere. It's much better than par.

Bart
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index afeb8d1c7102..750724601106 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -744,9 +744,7 @@  static int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
 
 struct acpi_gpio_lookup {
 	struct acpi_gpio_info info;
-	int index;
-	u16 pin_index;
-	bool active_low;
+	struct acpi_gpio_params par;
 	struct gpio_desc *desc;
 	int n;
 };
@@ -754,6 +752,7 @@  struct acpi_gpio_lookup {
 static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
 {
 	struct acpi_gpio_lookup *lookup = data;
+	struct acpi_gpio_params *par = &lookup->par;
 
 	if (ares->type != ACPI_RESOURCE_TYPE_GPIO)
 		return 1;
@@ -765,12 +764,12 @@  static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
 		u16 pin_index;
 
 		if (lookup->info.quirks & ACPI_GPIO_QUIRK_ONLY_GPIOIO && gpioint)
-			lookup->index++;
+			par->crs_entry_index++;
 
-		if (lookup->n++ != lookup->index)
+		if (lookup->n++ != par->crs_entry_index)
 			return 1;
 
-		pin_index = lookup->pin_index;
+		pin_index = par->line_index;
 		if (pin_index >= agpio->pin_table_length)
 			return 1;
 
@@ -796,7 +795,7 @@  static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
 			lookup->info.polarity = agpio->polarity;
 			lookup->info.triggering = agpio->triggering;
 		} else {
-			lookup->info.polarity = lookup->active_low;
+			lookup->info.polarity = par->active_low;
 		}
 
 		lookup->info.flags = acpi_gpio_to_gpiod_flags(agpio, lookup->info.polarity);
@@ -834,7 +833,8 @@  static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, const char *p
 				     struct acpi_gpio_lookup *lookup)
 {
 	struct fwnode_reference_args args;
-	unsigned int index = lookup->index;
+	struct acpi_gpio_params *par = &lookup->par;
+	unsigned int index = par->crs_entry_index;
 	unsigned int quirks = 0;
 	int ret;
 
@@ -857,9 +857,9 @@  static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, const char *p
 	if (args.nargs != 3)
 		return -EPROTO;
 
-	lookup->index = args.args[0];
-	lookup->pin_index = args.args[1];
-	lookup->active_low = !!args.args[2];
+	par->crs_entry_index = args.args[0];
+	par->line_index = args.args[1];
+	par->active_low = !!args.args[2];
 
 	lookup->info.adev = to_acpi_device_node(args.fwnode);
 	lookup->info.quirks = quirks;
@@ -897,10 +897,11 @@  static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
 						 struct acpi_gpio_info *info)
 {
 	struct acpi_gpio_lookup lookup;
+	struct acpi_gpio_params *par = &lookup.par;
 	int ret;
 
 	memset(&lookup, 0, sizeof(lookup));
-	lookup.index = index;
+	par->crs_entry_index = index;
 
 	if (propname) {
 		dev_dbg(&adev->dev, "GPIO: looking up %s\n", propname);
@@ -909,9 +910,9 @@  static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
 		if (ret)
 			return ERR_PTR(ret);
 
-		dev_dbg(&adev->dev, "GPIO: _DSD returned %s %d %u %u\n",
-			dev_name(&lookup.info.adev->dev), lookup.index,
-			lookup.pin_index, lookup.active_low);
+		dev_dbg(&adev->dev, "GPIO: _DSD returned %s %u %u %u\n",
+			dev_name(&lookup.info.adev->dev),
+			par->crs_entry_index, par->line_index, par->active_low);
 	} else {
 		dev_dbg(&adev->dev, "GPIO: looking up %d in _CRS\n", index);
 		lookup.info.adev = adev;
@@ -943,6 +944,7 @@  static struct gpio_desc *acpi_get_gpiod_from_data(struct fwnode_handle *fwnode,
 						  struct acpi_gpio_info *info)
 {
 	struct acpi_gpio_lookup lookup;
+	struct acpi_gpio_params *par = &lookup.par;
 	int ret;
 
 	if (!is_acpi_data_node(fwnode))
@@ -952,7 +954,7 @@  static struct gpio_desc *acpi_get_gpiod_from_data(struct fwnode_handle *fwnode,
 		return ERR_PTR(-EINVAL);
 
 	memset(&lookup, 0, sizeof(lookup));
-	lookup.index = index;
+	par->crs_entry_index = index;
 
 	ret = acpi_gpio_property_lookup(fwnode, propname, &lookup);
 	if (ret)