diff mbox series

[1/4] ucfw: Refactored switch_mode signature

Message ID 20231020123320.82500-2-boerge.struempfel@gmail.com
State Accepted
Headers show
Series Add compatibility with libgpiod v2.0 and higher | expand

Commit Message

Börge Strümpfel Oct. 20, 2023, 12:33 p.m. UTC
This commit aims to reduce the number of parameters, which have to be
given to the switch_mode function. This makes it much easier to add a
different variation of this function depending on the installed libgpiod
version.

Signed-off-by: Boerge Struempfel <boerge.struempfel@gmail.com>
---
 handlers/ucfw_handler.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Comments

Stefano Babic Oct. 24, 2023, 11:32 a.m. UTC | #1
On 20.10.23 14:33, Boerge Struempfel wrote:
> This commit aims to reduce the number of parameters, which have to be
> given to the switch_mode function. This makes it much easier to add a
> different variation of this function depending on the installed libgpiod
> version.
> 

I checked the code and by reading the API changes in libgpiod, this 
series is fine.

However, I have currently no hardware to test it - nice if someone will 
test it, and send Tested-by for inclusion.

Nevertheless, I set this series for inclusion, I will just wait a little.

Acked-by: Stefano Babic <stefano.babic@swupdate.org>

Best regards,
Stefano Babic

> Signed-off-by: Boerge Struempfel <boerge.struempfel@gmail.com>
> ---
>   handlers/ucfw_handler.c | 20 ++++++++++----------
>   1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/handlers/ucfw_handler.c b/handlers/ucfw_handler.c
> index 8d10a54..5bf23c0 100644
> --- a/handlers/ucfw_handler.c
> +++ b/handlers/ucfw_handler.c
> @@ -109,16 +109,17 @@ struct handler_priv {
>   	unsigned int nbytes;
>   };
>   
> -static int switch_mode(char *devreset, int resoffset, char *devprog, int progoffset, int mode)
> +
> +static int switch_mode(struct handler_priv *priv, int mode)
>   {
>   	struct gpiod_chip *chipreset, *chipprog;
>   	struct gpiod_line *linereset, *lineprog;
>   	int ret = 0;
>   	int status;
>   
> -	chipreset = gpiod_chip_open(devreset);
> -	if (strcmp(devreset, devprog))
> -		chipprog = gpiod_chip_open(devprog);
> +	chipreset = gpiod_chip_open(priv->reset.gpiodev);
> +	if (strcmp(priv->reset.gpiodev, priv->prog.gpiodev))
> +		chipprog = gpiod_chip_open(priv->prog.gpiodev);
>   	else
>   		chipprog = chipreset;
>   
> @@ -128,13 +129,13 @@ static int switch_mode(char *devreset, int resoffset, char *devprog, int progoff
>   		goto freegpios;
>   	}
>   
> -	linereset = gpiod_chip_get_line(chipreset, resoffset);
> -	lineprog = gpiod_chip_get_line(chipprog, progoffset);
> +	linereset = gpiod_chip_get_line(chipreset, priv->reset.offset);
> +	lineprog = gpiod_chip_get_line(chipprog, priv->prog.offset);
>   
>   	if (!linereset || !lineprog) {
>   		ERROR("Cannot get requested GPIOs: %d on %s and %d on %s",
> -			resoffset, devreset,
> -			progoffset, devprog);
> +			priv->reset.offset, priv->reset.gpiodev,
> +			priv->prog.offset, priv->prog.gpiodev);
>   		ret  =-ENODEV;
>   		goto freegpios;
>   	}
> @@ -378,8 +379,7 @@ static int prepare_update(struct handler_priv *priv,
>   	char msg[128];
>   	int len;
>   
> -	ret = switch_mode(priv->reset.gpiodev, priv->reset.offset,
> -			  priv->prog.gpiodev, priv->prog.offset, MODE_PROG);
> +	ret = switch_mode(priv, MODE_PROG);
>   	if (ret < 0) {
>   		return -ENODEV;
>   	}
diff mbox series

Patch

diff --git a/handlers/ucfw_handler.c b/handlers/ucfw_handler.c
index 8d10a54..5bf23c0 100644
--- a/handlers/ucfw_handler.c
+++ b/handlers/ucfw_handler.c
@@ -109,16 +109,17 @@  struct handler_priv {
 	unsigned int nbytes;
 };
 
-static int switch_mode(char *devreset, int resoffset, char *devprog, int progoffset, int mode)
+
+static int switch_mode(struct handler_priv *priv, int mode)
 {
 	struct gpiod_chip *chipreset, *chipprog;
 	struct gpiod_line *linereset, *lineprog;
 	int ret = 0;
 	int status;
 
-	chipreset = gpiod_chip_open(devreset);
-	if (strcmp(devreset, devprog))
-		chipprog = gpiod_chip_open(devprog);
+	chipreset = gpiod_chip_open(priv->reset.gpiodev);
+	if (strcmp(priv->reset.gpiodev, priv->prog.gpiodev))
+		chipprog = gpiod_chip_open(priv->prog.gpiodev);
 	else
 		chipprog = chipreset;
 
@@ -128,13 +129,13 @@  static int switch_mode(char *devreset, int resoffset, char *devprog, int progoff
 		goto freegpios;
 	}
 
-	linereset = gpiod_chip_get_line(chipreset, resoffset);
-	lineprog = gpiod_chip_get_line(chipprog, progoffset);
+	linereset = gpiod_chip_get_line(chipreset, priv->reset.offset);
+	lineprog = gpiod_chip_get_line(chipprog, priv->prog.offset);
 
 	if (!linereset || !lineprog) {
 		ERROR("Cannot get requested GPIOs: %d on %s and %d on %s",
-			resoffset, devreset,
-			progoffset, devprog);
+			priv->reset.offset, priv->reset.gpiodev,
+			priv->prog.offset, priv->prog.gpiodev);
 		ret  =-ENODEV;
 		goto freegpios;
 	}
@@ -378,8 +379,7 @@  static int prepare_update(struct handler_priv *priv,
 	char msg[128];
 	int len;
 
-	ret = switch_mode(priv->reset.gpiodev, priv->reset.offset,
-			  priv->prog.gpiodev, priv->prog.offset, MODE_PROG);
+	ret = switch_mode(priv, MODE_PROG);
 	if (ret < 0) {
 		return -ENODEV;
 	}