diff mbox series

[10/11] net: dsa: microchip: ksz8795: dynamic allocate memory for flush_dyn_mac_table

Message ID 20201118220357.22292-11-m.grzeschik@pengutronix.de (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: microchip: make ksz8795 driver more dynamic | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit fail Errors and warnings before: 7 this patch: 7
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 31 lines checked
netdev/build_allmodconfig_warn fail Errors and warnings before: 7 this patch: 7
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Michael Grzeschik Nov. 18, 2020, 10:03 p.m. UTC
To get the driver working with other chips using different port counts
the dyn_mac_table should be flushed depending on the amount of physical
ports.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>

---
v1: - based on "[PATCH v4 05/11] net: dsa: microchip: ksz8795: dynamica allocate memory for flush_dyn_mac_table"
    - lore: https://lore.kernel.org/netdev/20200803054442.20089-6-m.grzeschik@pengutronix.de/
---
 drivers/net/dsa/microchip/ksz8795.c     | 8 ++++++--
 drivers/net/dsa/microchip/ksz8795_reg.h | 2 --
 2 files changed, 6 insertions(+), 4 deletions(-)

Comments

Andrew Lunn Nov. 19, 2020, 1:21 a.m. UTC | #1
On Wed, Nov 18, 2020 at 11:03:56PM +0100, Michael Grzeschik wrote:
> To get the driver working with other chips using different port counts
> the dyn_mac_table should be flushed depending on the amount of physical
> ports.
> 
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
> 
> ---
> v1: - based on "[PATCH v4 05/11] net: dsa: microchip: ksz8795: dynamica allocate memory for flush_dyn_mac_table"
>     - lore: https://lore.kernel.org/netdev/20200803054442.20089-6-m.grzeschik@pengutronix.de/
> ---
>  drivers/net/dsa/microchip/ksz8795.c     | 8 ++++++--
>  drivers/net/dsa/microchip/ksz8795_reg.h | 2 --
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
> index 9ea5ec61513023f..418f71e5b90761c 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -750,11 +750,14 @@ static void ksz8795_port_stp_state_set(struct dsa_switch *ds, int port,
>  
>  static void ksz8795_flush_dyn_mac_table(struct ksz_device *dev, int port)
>  {
> -	u8 learn[TOTAL_PORT_NUM];
>  	int first, index, cnt;
>  	struct ksz_port *p;
> +	u8 *learn = kzalloc(dev->port_cnt, GFP_KERNEL);

Using DSA_MAX_PORTS makes things simpler.

      Andrew
Florian Fainelli Nov. 19, 2020, 3:12 a.m. UTC | #2
On 11/18/2020 2:03 PM, Michael Grzeschik wrote:
> To get the driver working with other chips using different port counts
> the dyn_mac_table should be flushed depending on the amount of physical
> ports.
> 
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
diff mbox series

Patch

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 9ea5ec61513023f..418f71e5b90761c 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -750,11 +750,14 @@  static void ksz8795_port_stp_state_set(struct dsa_switch *ds, int port,
 
 static void ksz8795_flush_dyn_mac_table(struct ksz_device *dev, int port)
 {
-	u8 learn[TOTAL_PORT_NUM];
 	int first, index, cnt;
 	struct ksz_port *p;
+	u8 *learn = kzalloc(dev->port_cnt, GFP_KERNEL);
 
-	if ((uint)port < TOTAL_PORT_NUM) {
+	if (!learn)
+		return;
+
+	if ((uint)port < dev->port_cnt) {
 		first = port;
 		cnt = port + 1;
 	} else {
@@ -779,6 +782,7 @@  static void ksz8795_flush_dyn_mac_table(struct ksz_device *dev, int port)
 		if (!(learn[index] & PORT_LEARN_DISABLE))
 			ksz_pwrite8(dev, index, P_STP_CTRL, learn[index]);
 	}
+	kfree(learn);
 }
 
 static int ksz8795_port_vlan_filtering(struct dsa_switch *ds, int port,
diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/microchip/ksz8795_reg.h
index 6377165a236fdf3..681d19ab27b89da 100644
--- a/drivers/net/dsa/microchip/ksz8795_reg.h
+++ b/drivers/net/dsa/microchip/ksz8795_reg.h
@@ -846,8 +846,6 @@ 
 
 #define KS_PRIO_IN_REG			4
 
-#define TOTAL_PORT_NUM			5
-
 #define KSZ8795_COUNTER_NUM		0x20
 
 /* Common names used by other drivers */