Re: [PATCH] staging: pi433: replace simple switch statements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2018-06-24 at 11:42 +0200, Valentin Vidic wrote:
> Use const array to map switch cases to resulting values.

I suggest you make the const arrays the same type
as the argument in the function being called.

> diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
[]
> @@ -111,27 +111,22 @@ static inline int rf69_read_mod_write(struct spi_device *spi, u8 reg,
>  
>  int rf69_set_mode(struct spi_device *spi, enum mode mode)
>  {
> -	switch (mode) {
> -	case transmit:
> -		return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE,
> -					   OPMODE_MODE_TRANSMIT);
[]
> +	static const int mode_map[] = {
> +		[transmit] = OPMODE_MODE_TRANSMIT,
> +		[receive] = OPMODE_MODE_RECEIVE,
> +		[synthesizer] = OPMODE_MODE_SYNTHESIZER,
> +		[standby] = OPMODE_MODE_STANDBY,
> +		[mode_sleep] = OPMODE_MODE_SLEEP,
> +	};
[]
> +	return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE,
> +				   mode_map[mode]);

drivers/staging/pi433/rf69.c:static inline int rf69_read_mod_write(struct spi_device *spi, u8 reg,
drivers/staging/pi433/rf69.c-                                 u8 mask, u8 value)

so u8 here.

etc...

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux