[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <36befceb2334197cce5cd44a61f86f38b870d54c.camel@perches.com>
Date: Sun, 24 Jun 2018 08:26:32 -0700
From: Joe Perches <joe@...ches.com>
To: Valentin Vidic <Valentin.Vidic@...Net.hr>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Simon Sandström <simon@...anor.nu>,
Marcus Wolf <linux@...f-Entwicklungen.de>,
Luca Söthe <luca@...l.me>,
Marcin Ciupak <marcin.s.ciupak@...il.com>,
Michael Panzlaff <michael.panzlaff@....de>,
Derek Robson <robsonde@...il.com>, devel@...verdev.osuosl.org,
linux-kernel@...r.kernel.org, Hugo Lefeuvre <hle@....eu.com>,
Dan Carpenter <dan.carpenter@...cle.com>
Subject: Re: [PATCH] staging: pi433: replace simple switch statements
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...
Powered by blists - more mailing lists