mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <Arun.Ramadoss@microchip.com>
To: <andrew@lunn.ch>, <olteanv@gmail.com>, <davem@davemloft.net>,
	<Woojung.Huh@microchip.com>, <pabeni@redhat.com>,
	<o.rempel@pengutronix.de>, <edumazet@google.com>,
	<f.fainelli@gmail.com>, <kuba@kernel.org>
Cc: <kernel@pengutronix.de>, <san@skov.dk>,
	<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
	<UNGLinuxDriver@microchip.com>
Subject: Re: [PATCH net-next v1 4/8] net: dsa: microchip: ksz8: Refactor ksz8_r_dyn_mac_table() for readability
Date: Tue, 2 Apr 2024 15:44:30 +0000	[thread overview]
Message-ID: <e559c5c81e90039f17b555b66c5b3837d410c489.camel@microchip.com> (raw)
In-Reply-To: <20240402131339.1525330-5-o.rempel@pengutronix.de>

Hi Oleksij,

On Tue, 2024-04-02 at 15:13 +0200, Oleksij Rempel wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> Move the code out of a long if statement scope in
> ksz8_r_dyn_mac_table()
> to improve code readability.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/dsa/microchip/ksz8795.c | 60 +++++++++++++++----------
> ----
>  1 file changed, 31 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz8795.c
> b/drivers/net/dsa/microchip/ksz8795.c
> index b70aa2c0a85ec..1962195e16a6f 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -416,7 +416,9 @@ static int ksz8_r_dyn_mac_table(struct ksz_device
> *dev, u16 addr, u8 *mac_addr,
>         const u32 *masks;
>         const u16 *regs;
>         u16 ctrl_addr;
> +       u64 buf = 0;
>         u8 data;
> +       int cnt;
>         int rc;

If rc is initialized with 0, we don't need to assign rc = 0 in the
success path.

But otherwise
Acked-by: Arun Ramadoss <arun.ramadoss@microchip.com>

> 
>         shifts = dev->info->shifts;
> @@ -432,38 +434,38 @@ static int ksz8_r_dyn_mac_table(struct
> ksz_device *dev, u16 addr, u8 *mac_addr,
>         if (rc == -EAGAIN) {
>                 if (addr == 0)
>                         *entries = 0;
> +               goto unlock_alu;
>         } else if (rc == -ENXIO) {
>                 *entries = 0;
> -       /* At least one valid entry in the table. */
> -       } else {
> -               u64 buf = 0;
> -               int cnt;
> -
> -               ksz_read64(dev, regs[REG_IND_DATA_HI], &buf);
> -               data_hi = (u32)(buf >> 32);
> -               data_lo = (u32)buf;
> -
> -               /* Check out how many valid entry in the table. */
> -               cnt = data & masks[DYNAMIC_MAC_TABLE_ENTRIES_H];
> -               cnt <<= shifts[DYNAMIC_MAC_ENTRIES_H];
> -               cnt |= (data_hi & masks[DYNAMIC_MAC_TABLE_ENTRIES])
> >>
> -                       shifts[DYNAMIC_MAC_ENTRIES];
> -               *entries = cnt + 1;
> -
> -               *fid = (data_hi & masks[DYNAMIC_MAC_TABLE_FID]) >>
> -                       shifts[DYNAMIC_MAC_FID];
> -               *src_port = (data_hi &
> masks[DYNAMIC_MAC_TABLE_SRC_PORT]) >>
> -                       shifts[DYNAMIC_MAC_SRC_PORT];
> -
> -               mac_addr[5] = (u8)data_lo;
> -               mac_addr[4] = (u8)(data_lo >> 8);
> -               mac_addr[3] = (u8)(data_lo >> 16);
> -               mac_addr[2] = (u8)(data_lo >> 24);
> -
> -               mac_addr[1] = (u8)data_hi;
> -               mac_addr[0] = (u8)(data_hi >> 8);
> -               rc = 0;
> +               goto unlock_alu;
>         }
> +
> +       ksz_read64(dev, regs[REG_IND_DATA_HI], &buf);
> +       data_hi = (u32)(buf >> 32);
> +       data_lo = (u32)buf;
> +
> +       /* Check out how many valid entry in the table. */
> +       cnt = data & masks[DYNAMIC_MAC_TABLE_ENTRIES_H];
> +       cnt <<= shifts[DYNAMIC_MAC_ENTRIES_H];
> +       cnt |= (data_hi & masks[DYNAMIC_MAC_TABLE_ENTRIES]) >>
> +               shifts[DYNAMIC_MAC_ENTRIES];
> +       *entries = cnt + 1;
> +
> +       *fid = (data_hi & masks[DYNAMIC_MAC_TABLE_FID]) >>
> +               shifts[DYNAMIC_MAC_FID];
> +       *src_port = (data_hi & masks[DYNAMIC_MAC_TABLE_SRC_PORT]) >>
> +               shifts[DYNAMIC_MAC_SRC_PORT];
> +
> +       mac_addr[5] = (u8)data_lo;
> +       mac_addr[4] = (u8)(data_lo >> 8);
> +       mac_addr[3] = (u8)(data_lo >> 16);
> +       mac_addr[2] = (u8)(data_lo >> 24);
> +
> +       mac_addr[1] = (u8)data_hi;
> +       mac_addr[0] = (u8)(data_hi >> 8);
> +       rc = 0;
> +
> +unlock_alu:
>         mutex_unlock(&dev->alu_mutex);
> 
>         return rc;
> --
> 2.39.2
> 

  reply	other threads:[~2024-04-02 15:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02 13:13 [PATCH net-next v1 0/8] net: dsa: microchip: ksz8: refactor FDB dump path Oleksij Rempel
2024-04-02 13:13 ` [PATCH net-next v1 1/8] net: dsa: microchip: Remove unused FDB timestamp support in ksz8_r_dyn_mac_table() Oleksij Rempel
2024-04-02 15:28   ` Arun.Ramadoss
2024-04-02 13:13 ` [PATCH net-next v1 2/8] net: dsa: microchip: Make ksz8_r_dyn_mac_table() static Oleksij Rempel
2024-04-02 15:29   ` Arun.Ramadoss
2024-04-02 13:13 ` [PATCH net-next v1 3/8] net: dsa: microchip: ksz8: Refactor ksz8_fdb_dump() Oleksij Rempel
2024-04-02 15:37   ` Arun.Ramadoss
2024-04-02 13:13 ` [PATCH net-next v1 4/8] net: dsa: microchip: ksz8: Refactor ksz8_r_dyn_mac_table() for readability Oleksij Rempel
2024-04-02 15:44   ` Arun.Ramadoss [this message]
2024-04-02 17:07     ` Jakub Kicinski
2024-04-02 13:13 ` [PATCH net-next v1 5/8] net: dsa: microchip: ksz8: Unify variable naming in ksz8_r_dyn_mac_table() Oleksij Rempel
2024-04-02 15:45   ` Arun.Ramadoss
2024-04-02 13:13 ` [PATCH net-next v1 6/8] net: dsa: microchip: ksz8_r_dyn_mac_table(): ksz: do not return EAGAIN on timeout Oleksij Rempel
2024-04-03  8:21   ` Arun.Ramadoss
2024-04-02 13:13 ` [PATCH net-next v1 7/8] net: dsa: microchip: ksz8_r_dyn_mac_table(): return read/write error if we got any Oleksij Rempel
2024-04-02 15:59   ` Arun.Ramadoss
2024-04-02 13:13 ` [PATCH net-next v1 8/8] net: dsa: microchip: ksz8_r_dyn_mac_table(): use entries variable to signal 0 entries Oleksij Rempel
2024-04-03  8:18   ` Arun.Ramadoss
2024-04-03 11:21 ` [PATCH net-next v1 0/8] net: dsa: microchip: ksz8: refactor FDB dump path Vladimir Oltean

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=e559c5c81e90039f17b555b66c5b3837d410c489.camel@microchip.com \
    --to=arun.ramadoss@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=Woojung.Huh@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=san@skov.dk \
    /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

all inboxes | Powered by JetHome®