Linux Serial subsystem development
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	linux-serial@vger.kernel.org,
	"Thomas Bogendoerfer" <tsbogend@alpha.franken.de>,
	linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: inux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] serial: 8250_rt288x: Remove unnecessary UART_REG_UNMAPPED
Date: Fri, 30 Dec 2022 14:14:29 +0100	[thread overview]
Message-ID: <9ad399f9-7d27-b541-2379-355f3a8258ae@linaro.org> (raw)
In-Reply-To: <20221230114603.16946-4-ilpo.jarvinen@linux.intel.com>

Hi Ilpo,

On 30/12/22 12:46, Ilpo Järvinen wrote:
> As unmapped registers are at the tail of the array, the ARRAY_SIZE()
> condition will catch them just fine. No need to define special
> value for them.

True but fragile example...

> Also, let the compiler to calculate the size of the array instead of
> providing it manually.
> 
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
>   drivers/tty/serial/8250/8250_rt288x.c | 16 ++++------------
>   1 file changed, 4 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_rt288x.c b/drivers/tty/serial/8250/8250_rt288x.c
> index 3015afb99722..da8be9a802c1 100644
> --- a/drivers/tty/serial/8250/8250_rt288x.c
> +++ b/drivers/tty/serial/8250/8250_rt288x.c
> @@ -14,10 +14,8 @@
>   
>   #define RT288X_DL	0x28
>   
> -#define UART_REG_UNMAPPED	-1


> -static const s8 au_io_out_map[8] = {
> +static const s8 au_io_out_map[] = {
>   	[UART_TX]	= 1,
>   	[UART_IER]	= 2,
>   	[UART_FCR]	= 4,
>   	[UART_LCR]	= 5,
>   	[UART_MCR]	= 6,
> -	[UART_LSR]	= UART_REG_UNMAPPED,
> -	[UART_MSR]	= UART_REG_UNMAPPED,
> -	[UART_SCR]	= UART_REG_UNMAPPED,

If someone were to re-add an unlikely single

         [UART_SCR] = 42,

The array will also contain these hidden entries:

         [UART_LSR] = 0,
         [UART_MSR] = 0,

And these 2 registers end mapped.

>   };

Trying to 'optimize' array size when the array is index-initialized
can be bug-prone.

>   static unsigned int au_serial_in(struct uart_port *p, int offset)
> @@ -44,8 +38,7 @@ static unsigned int au_serial_in(struct uart_port *p, int offset)
>   	if (offset >= ARRAY_SIZE(au_io_in_map))
>   		return UINT_MAX;
>   	offset = au_io_in_map[offset];
> -	if (offset == UART_REG_UNMAPPED)
> -		return UINT_MAX;
> +
>   	return __raw_readl(p->membase + (offset << p->regshift));
>   }
Regards,

Phil.

      reply	other threads:[~2022-12-30 13:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-30 11:46 [PATCH 0/3] serial: Separate RT288x/Au1xxx code into own file Ilpo Järvinen
2022-12-30 11:46 ` [PATCH 1/3] serial: 8250: RT288x/Au1xxx code away from core Ilpo Järvinen
2022-12-30 11:46 ` [PATCH 2/3] serial: 8250_rt288x: Name non-standard divisor latch reg Ilpo Järvinen
2022-12-30 13:04   ` Philippe Mathieu-Daudé
2022-12-30 11:46 ` [PATCH 3/3] serial: 8250_rt288x: Remove unnecessary UART_REG_UNMAPPED Ilpo Järvinen
2022-12-30 13:14   ` Philippe Mathieu-Daudé [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9ad399f9-7d27-b541-2379-355f3a8258ae@linaro.org \
    --to=philmd@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=inux-kernel@vger.kernel.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox