]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: kzalloc + kcalloc to kzalloc 22651/head
authorRosen Penev <rosenp@gmail.com>
Tue, 7 Apr 2026 22:03:42 +0000 (15:03 -0700)
committerJonas Jelonek <jelonek.jonas@gmail.com>
Tue, 26 May 2026 08:30:40 +0000 (10:30 +0200)
Use a flexible array member to combine allocations.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/22651
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/common.c
target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/rtl-otto.h

index 8b267a4f3b38b5183c0d095f5803a9d9a590d397..6e0197d2b391694f1732415edf209ee6a58e77bd 100644 (file)
@@ -1560,6 +1560,7 @@ static int rtl83xx_sw_probe(struct platform_device *pdev)
 {
        struct rtl838x_switch_priv *priv;
        struct device *dev = &pdev->dev;
+       const struct rtldsa_config *r;
        u64 bpdu_mask;
        int err = 0;
 
@@ -1579,11 +1580,12 @@ static int rtl83xx_sw_probe(struct platform_device *pdev)
        /* Initialize access to RTL switch tables */
        rtl_table_init();
 
-       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+       r = device_get_match_data(&pdev->dev);
+       priv = devm_kzalloc(dev, struct_size(priv, msts, r->n_mst - 1), GFP_KERNEL);
        if (!priv)
                return -ENOMEM;
 
-       priv->r = device_get_match_data(&pdev->dev);
+       priv->r = r;
 
        priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL);
        if (!priv->ds)
@@ -1620,12 +1622,6 @@ static int rtl83xx_sw_probe(struct platform_device *pdev)
                return err;
        }
 
-       priv->msts = devm_kcalloc(priv->dev,
-                                 priv->r->n_mst - 1, sizeof(struct rtldsa_mst),
-                                 GFP_KERNEL);
-       if (!priv->msts)
-               return -ENOMEM;
-
        priv->wq = create_singlethread_workqueue("rtl83xx");
        if (!priv->wq) {
                dev_err(dev, "Error creating workqueue: %d\n", err);
index aa747b2c750ce7a07eccdaa44c9bc7367fdf6a51..90efb8540c04b0efd6c3ccb44f595a3c6eb15569 100644 (file)
@@ -1555,11 +1555,6 @@ struct rtl838x_switch_priv {
        u16 intf_mtus[MAX_INTF_MTUS];
        int intf_mtu_count[MAX_INTF_MTUS];
 
-       /**
-        * @msts: MSTI to HW MST slot allocations. index 0 is for HW slot 1 because CIST is
-        * not stored in @msts
-        */
-       struct rtldsa_mst *msts;
        struct delayed_work counters_work;
 
        /**
@@ -1568,6 +1563,12 @@ struct rtl838x_switch_priv {
         * periodically.
         */
        struct mutex counters_lock;
+
+       /**
+        * @msts: MSTI to HW MST slot allocations. index 0 is for HW slot 1 because CIST is
+        * not stored in @msts
+        */
+       struct rtldsa_mst msts[];
 };
 
 struct fdb_update_work {