rswitch: Use unsigned int for port related array index
authorYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tue, 17 Oct 2023 11:34:01 +0000 (20:34 +0900)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 19 Oct 2023 08:59:33 +0000 (10:59 +0200)
Array index should not be negative, so modify the condition of
rswitch_for_each_enabled_port_continue_reverse() macro, and then
use unsigned int instead.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/renesas/rswitch.c
drivers/net/ethernet/renesas/rswitch.h

index 112e605..e5a41e7 100644 (file)
@@ -1405,7 +1405,8 @@ static void rswitch_ether_port_deinit_one(struct rswitch_device *rdev)
 
 static int rswitch_ether_port_init_all(struct rswitch_private *priv)
 {
-       int i, err;
+       unsigned int i;
+       int err;
 
        rswitch_for_each_enabled_port(priv, i) {
                err = rswitch_ether_port_init_one(priv->rdev[i]);
@@ -1786,7 +1787,8 @@ static void rswitch_device_free(struct rswitch_private *priv, int index)
 
 static int rswitch_init(struct rswitch_private *priv)
 {
-       int i, err;
+       unsigned int i;
+       int err;
 
        for (i = 0; i < RSWITCH_NUM_PORTS; i++)
                rswitch_etha_init(priv, i);
@@ -1816,7 +1818,7 @@ static int rswitch_init(struct rswitch_private *priv)
        for (i = 0; i < RSWITCH_NUM_PORTS; i++) {
                err = rswitch_device_alloc(priv, i);
                if (err < 0) {
-                       for (i--; i >= 0; i--)
+                       for (; i-- > 0; )
                                rswitch_device_free(priv, i);
                        goto err_device_alloc;
                }
@@ -1959,7 +1961,7 @@ static int renesas_eth_sw_probe(struct platform_device *pdev)
 
 static void rswitch_deinit(struct rswitch_private *priv)
 {
-       int i;
+       unsigned int i;
 
        rswitch_gwca_hw_deinit(priv);
        rcar_gen4_ptp_unregister(priv->ptp_priv);
index 04f49a7..27c9d38 100644 (file)
@@ -20,7 +20,7 @@
                else
 
 #define rswitch_for_each_enabled_port_continue_reverse(priv, i)        \
-       for (i--; i >= 0; i--)                                  \
+       for (; i-- > 0; )                                       \
                if (priv->rdev[i]->disabled)                    \
                        continue;                               \
                else