diff mbox series

[net-next] net: dsa: microchip: Uninitialized variable in ksz9477_acl_move_entries()

Message ID 2f58ca9a-9ac5-460a-98a4-aa8304f2348a@moroto.mountain (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: dsa: microchip: Uninitialized variable in ksz9477_acl_move_entries() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1340 this patch: 1340
netdev/cc_maintainers success CCed 11 of 11 maintainers
netdev/build_clang success Errors and warnings before: 1363 this patch: 1363
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1363 this patch: 1363
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Dan Carpenter Sept. 27, 2023, 12:53 p.m. UTC
Smatch complains that if "src_idx" equals "dst_idx" then
ksz9477_validate_and_get_src_count() doesn't initialized "src_count".
Set it to zero for this situation.

Fixes: 002841be134e ("net: dsa: microchip: Add partial ACL support for ksz9477 switches")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/net/dsa/microchip/ksz9477_acl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Oleksij Rempel Sept. 27, 2023, 2:46 p.m. UTC | #1
On Wed, Sep 27, 2023 at 03:53:37PM +0300, Dan Carpenter wrote:
> Smatch complains that if "src_idx" equals "dst_idx" then
> ksz9477_validate_and_get_src_count() doesn't initialized "src_count".
> Set it to zero for this situation.
> 
> Fixes: 002841be134e ("net: dsa: microchip: Add partial ACL support for ksz9477 switches")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>

Thank you!

> ---
>  drivers/net/dsa/microchip/ksz9477_acl.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz9477_acl.c b/drivers/net/dsa/microchip/ksz9477_acl.c
> index 06d74c19eb94..e554cd4a024b 100644
> --- a/drivers/net/dsa/microchip/ksz9477_acl.c
> +++ b/drivers/net/dsa/microchip/ksz9477_acl.c
> @@ -554,7 +554,8 @@ static int ksz9477_acl_move_entries(struct ksz_device *dev, int port,
>  	struct ksz9477_acl_entry buffer[KSZ9477_ACL_MAX_ENTRIES];
>  	struct ksz9477_acl_priv *acl = dev->ports[port].acl_priv;
>  	struct ksz9477_acl_entries *acles = &acl->acles;
> -	int src_count, ret, dst_count;
> +	int ret, dst_count;
> +	int src_count = 0;
>  
>  	ret = ksz9477_validate_and_get_src_count(dev, port, src_idx, dst_idx,
>  						 &src_count, &dst_count);
> -- 
> 2.39.2
> 
> 
>
Vladimir Oltean Oct. 2, 2023, 3:28 p.m. UTC | #2
Hi Oleksij,

On Wed, Sep 27, 2023 at 04:46:24PM +0200, Oleksij Rempel wrote:
> On Wed, Sep 27, 2023 at 03:53:37PM +0300, Dan Carpenter wrote:
> > Smatch complains that if "src_idx" equals "dst_idx" then
> > ksz9477_validate_and_get_src_count() doesn't initialized "src_count".
> > Set it to zero for this situation.
> > 
> > Fixes: 002841be134e ("net: dsa: microchip: Add partial ACL support for ksz9477 switches")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> 
> Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>
> 
> Thank you!
> 
> > ---
> >  drivers/net/dsa/microchip/ksz9477_acl.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz9477_acl.c b/drivers/net/dsa/microchip/ksz9477_acl.c
> > index 06d74c19eb94..e554cd4a024b 100644
> > --- a/drivers/net/dsa/microchip/ksz9477_acl.c
> > +++ b/drivers/net/dsa/microchip/ksz9477_acl.c
> > @@ -554,7 +554,8 @@ static int ksz9477_acl_move_entries(struct ksz_device *dev, int port,
> >  	struct ksz9477_acl_entry buffer[KSZ9477_ACL_MAX_ENTRIES];
> >  	struct ksz9477_acl_priv *acl = dev->ports[port].acl_priv;
> >  	struct ksz9477_acl_entries *acles = &acl->acles;
> > -	int src_count, ret, dst_count;
> > +	int ret, dst_count;
> > +	int src_count = 0;
> >  
> >  	ret = ksz9477_validate_and_get_src_count(dev, port, src_idx, dst_idx,
> >  						 &src_count, &dst_count);
> > -- 
> > 2.39.2
> > 
> > 
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

For the case where src_idx == dst_idx that Dan points out, is this patch
sufficient to ensure that ksz9477_acl_move_entries() will not execute
unwanted code paths? For example, it will still call ksz9477_move_entries_upwards(),
which from what I can tell, will do something given the way in which it's written.

Perhaps it would be better to move this line:

	/* Nothing to do */
	if (src_idx == dst_idx)
		return 0;

outside of ksz9477_validate_and_get_src_count() and into its single caller,
ksz9477_acl_move_entries()?
Paolo Abeni Oct. 5, 2023, 8:06 a.m. UTC | #3
On Mon, 2023-10-02 at 18:28 +0300, Vladimir Oltean wrote:
> Hi Oleksij,
> 
> On Wed, Sep 27, 2023 at 04:46:24PM +0200, Oleksij Rempel wrote:
> > On Wed, Sep 27, 2023 at 03:53:37PM +0300, Dan Carpenter wrote:
> > > Smatch complains that if "src_idx" equals "dst_idx" then
> > > ksz9477_validate_and_get_src_count() doesn't initialized "src_count".
> > > Set it to zero for this situation.
> > > 
> > > Fixes: 002841be134e ("net: dsa: microchip: Add partial ACL support for ksz9477 switches")
> > > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > 
> > Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > 
> > Thank you!
> > 
> > > ---
> > >  drivers/net/dsa/microchip/ksz9477_acl.c | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/net/dsa/microchip/ksz9477_acl.c b/drivers/net/dsa/microchip/ksz9477_acl.c
> > > index 06d74c19eb94..e554cd4a024b 100644
> > > --- a/drivers/net/dsa/microchip/ksz9477_acl.c
> > > +++ b/drivers/net/dsa/microchip/ksz9477_acl.c
> > > @@ -554,7 +554,8 @@ static int ksz9477_acl_move_entries(struct ksz_device *dev, int port,
> > >  	struct ksz9477_acl_entry buffer[KSZ9477_ACL_MAX_ENTRIES];
> > >  	struct ksz9477_acl_priv *acl = dev->ports[port].acl_priv;
> > >  	struct ksz9477_acl_entries *acles = &acl->acles;
> > > -	int src_count, ret, dst_count;
> > > +	int ret, dst_count;
> > > +	int src_count = 0;
> > >  
> > >  	ret = ksz9477_validate_and_get_src_count(dev, port, src_idx, dst_idx,
> > >  						 &src_count, &dst_count);
> > > -- 
> > > 2.39.2
> > > 
> > > 
> > > 
> > 
> > -- 
> > Pengutronix e.K.                           |                             |
> > Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> > 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> > Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 
> For the case where src_idx == dst_idx that Dan points out, is this patch
> sufficient to ensure that ksz9477_acl_move_entries() will not execute
> unwanted code paths? For example, it will still call ksz9477_move_entries_upwards(),
> which from what I can tell, will do something given the way in which it's written.
> 
> Perhaps it would be better to move this line:
> 
> 	/* Nothing to do */
> 	if (src_idx == dst_idx)
> 		return 0;
> 
> outside of ksz9477_validate_and_get_src_count() and into its single caller,
> ksz9477_acl_move_entries()?

Additionally, it looks like that when (src_idx == dst_idx) even
dst_count is not initialized but is still later used.

Cheers,

Paolo
Oleksij Rempel Oct. 6, 2023, 10:45 a.m. UTC | #4
Hi Vladimir, Paolo,

On Thu, Oct 05, 2023 at 10:06:22AM +0200, Paolo Abeni wrote:
> On Mon, 2023-10-02 at 18:28 +0300, Vladimir Oltean wrote:
> > Hi Oleksij,
> > 
> > On Wed, Sep 27, 2023 at 04:46:24PM +0200, Oleksij Rempel wrote:
> > > On Wed, Sep 27, 2023 at 03:53:37PM +0300, Dan Carpenter wrote:
> > > > Smatch complains that if "src_idx" equals "dst_idx" then
> > > > ksz9477_validate_and_get_src_count() doesn't initialized "src_count".
> > > > Set it to zero for this situation.
> > > > 
> > > > Fixes: 002841be134e ("net: dsa: microchip: Add partial ACL support for ksz9477 switches")
> > > > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > > 
> > > Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > > 
> > > Thank you!
> > > 
> > > > ---
> > > >  drivers/net/dsa/microchip/ksz9477_acl.c | 3 ++-
> > > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/net/dsa/microchip/ksz9477_acl.c b/drivers/net/dsa/microchip/ksz9477_acl.c
> > > > index 06d74c19eb94..e554cd4a024b 100644
> > > > --- a/drivers/net/dsa/microchip/ksz9477_acl.c
> > > > +++ b/drivers/net/dsa/microchip/ksz9477_acl.c
> > > > @@ -554,7 +554,8 @@ static int ksz9477_acl_move_entries(struct ksz_device *dev, int port,
> > > >  	struct ksz9477_acl_entry buffer[KSZ9477_ACL_MAX_ENTRIES];
> > > >  	struct ksz9477_acl_priv *acl = dev->ports[port].acl_priv;
> > > >  	struct ksz9477_acl_entries *acles = &acl->acles;
> > > > -	int src_count, ret, dst_count;
> > > > +	int ret, dst_count;
> > > > +	int src_count = 0;
> > > >  
> > > >  	ret = ksz9477_validate_and_get_src_count(dev, port, src_idx, dst_idx,
> > > >  						 &src_count, &dst_count);
> > > > -- 
> > > > 2.39.2
> > > > 
> > > > 
> > > > 
> > > 
> > > -- 
> > > Pengutronix e.K.                           |                             |
> > > Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> > > 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> > > Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> > 
> > For the case where src_idx == dst_idx that Dan points out, is this patch
> > sufficient to ensure that ksz9477_acl_move_entries() will not execute
> > unwanted code paths? For example, it will still call ksz9477_move_entries_upwards(),
> > which from what I can tell, will do something given the way in which it's written.
> > 
> > Perhaps it would be better to move this line:
> > 
> > 	/* Nothing to do */
> > 	if (src_idx == dst_idx)
> > 		return 0;
> > 
> > outside of ksz9477_validate_and_get_src_count() and into its single caller,
> > ksz9477_acl_move_entries()?
> 
> Additionally, it looks like that when (src_idx == dst_idx) even
> dst_count is not initialized but is still later used.

Ack, moving if (src_idx == dst_idx) to ksz9477_acl_move_entries() is the
proper fix.

Regards,
Oleksij
diff mbox series

Patch

diff --git a/drivers/net/dsa/microchip/ksz9477_acl.c b/drivers/net/dsa/microchip/ksz9477_acl.c
index 06d74c19eb94..e554cd4a024b 100644
--- a/drivers/net/dsa/microchip/ksz9477_acl.c
+++ b/drivers/net/dsa/microchip/ksz9477_acl.c
@@ -554,7 +554,8 @@  static int ksz9477_acl_move_entries(struct ksz_device *dev, int port,
 	struct ksz9477_acl_entry buffer[KSZ9477_ACL_MAX_ENTRIES];
 	struct ksz9477_acl_priv *acl = dev->ports[port].acl_priv;
 	struct ksz9477_acl_entries *acles = &acl->acles;
-	int src_count, ret, dst_count;
+	int ret, dst_count;
+	int src_count = 0;
 
 	ret = ksz9477_validate_and_get_src_count(dev, port, src_idx, dst_idx,
 						 &src_count, &dst_count);