Re: [PATCH] staging: pi433: remove rf69_get_flag function resolving enum conflict

From: Dan Carpenter
Date: Mon Feb 28 2022 - 01:33:23 EST


Looks good.

Reviewed-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

On Sat, Feb 26, 2022 at 11:40:33AM +1300, Paulo Miguel Almeida wrote:
> The reason why rf69_get_flag() existed was to provide a high-level way
> to obtain values out of 1 (of 2) flags registers using bit masking. The
> idea was to map the possible flag values found in the data sheet like
> shown in page 70 of the RFM69HCW datasheet.
>
> However, due to the fact that enums values in C must be unique, there
> was a naming conflict on 'fifo_not_empty' which is used by the
> tx_start_condition enum. So the author decided to create a 'fifo_empty'
> one which would negate the value that comes from the flag register as
> the solution to that conflict (which is very confusing).
>
> this patch removes rf69_get_flag function which subsequently solves the
> enum redeclaration problem so kernel developers can follow the data
> sheet more easily.
>
> Signed-off-by: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@xxxxxxxxx>
> ---
> drivers/staging/pi433/pi433_if.c | 8 +++---
> drivers/staging/pi433/rf69.c | 44 -------------------------------
> drivers/staging/pi433/rf69.h | 1 -
> drivers/staging/pi433/rf69_enum.h | 20 --------------
> 4 files changed, 4 insertions(+), 69 deletions(-)

You don't really need to write a long commit message for a commit which
deletes 69 - 4 = 65 lines. Just say "Remove pointless rf69_get_flag()
function and call rf69_read_reg() directly. This cleanup removes 65
lines of code and it more obvious to read."

>
> diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
> index 069255f023c8..3f3e863e6cc8 100644
> --- a/drivers/staging/pi433/pi433_if.c
> +++ b/drivers/staging/pi433/pi433_if.c
> @@ -434,7 +434,7 @@ static int pi433_receive(void *data)
> return retval;
>
> /* now check RSSI, if low wait for getting high (RSSI interrupt) */
> - while (!rf69_get_flag(dev->spi, rssi_exceeded_threshold)) {
> + while (!(rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_RSSI)) {
> /* allow tx to interrupt us while waiting for high RSSI */
> dev->interrupt_rx_allowed = true;
> wake_up_interruptible(&dev->tx_wait_queue);
> @@ -442,8 +442,8 @@ static int pi433_receive(void *data)
> /* wait for RSSI level to become high */
> dev_dbg(dev->dev, "rx: going to wait for high RSSI level\n");
> retval = wait_event_interruptible(dev->rx_wait_queue,
> - rf69_get_flag(dev->spi,
> - rssi_exceeded_threshold));
> + rf69_read_reg(spi, REG_IRQFLAGS1)
> + & MASK_IRQFLAGS1_RSSI);

The & character should go on the first line.

rf69_read_reg(spi, REG_IRQFLAGS1) &
MASK_IRQFLAGS1_RSSI);

But that can be done in a follow on patch if you want. Or you can
leave it as-is.

regards,
dan carpenter