]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net: ibm/emac: allocate dummy net_device dynamically
authorBreno Leitao <leitao@debian.org>
Mon, 22 Apr 2024 12:39:00 +0000 (05:39 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 24 Apr 2024 11:00:17 +0000 (12:00 +0100)
Embedding net_device into structures prohibits the usage of flexible
arrays in the net_device structure. For more details, see the discussion
at [1].

Un-embed the net_device from the private struct by converting it
into a pointer. Then use the leverage the new alloc_netdev_dummy()
helper to allocate and initialize dummy devices.

[1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/

Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/ibm/emac/mal.c
drivers/net/ethernet/ibm/emac/mal.h

index 2439f7e96e056ce187db09ded4a8e6db8a0d451a..d92dd9c83031ee48b14ac744ced49c7740cdfe7a 100644 (file)
@@ -605,9 +605,13 @@ static int mal_probe(struct platform_device *ofdev)
        INIT_LIST_HEAD(&mal->list);
        spin_lock_init(&mal->lock);
 
-       init_dummy_netdev(&mal->dummy_dev);
+       mal->dummy_dev = alloc_netdev_dummy(0);
+       if (!mal->dummy_dev) {
+               err = -ENOMEM;
+               goto fail_unmap;
+       }
 
-       netif_napi_add_weight(&mal->dummy_dev, &mal->napi, mal_poll,
+       netif_napi_add_weight(mal->dummy_dev, &mal->napi, mal_poll,
                              CONFIG_IBM_EMAC_POLL_WEIGHT);
 
        /* Load power-on reset defaults */
@@ -637,7 +641,7 @@ static int mal_probe(struct platform_device *ofdev)
                                          GFP_KERNEL);
        if (mal->bd_virt == NULL) {
                err = -ENOMEM;
-               goto fail_unmap;
+               goto fail_dummy;
        }
 
        for (i = 0; i < mal->num_tx_chans; ++i)
@@ -703,6 +707,8 @@ static int mal_probe(struct platform_device *ofdev)
        free_irq(mal->serr_irq, mal);
  fail2:
        dma_free_coherent(&ofdev->dev, bd_size, mal->bd_virt, mal->bd_dma);
+ fail_dummy:
+       free_netdev(mal->dummy_dev);
  fail_unmap:
        dcr_unmap(mal->dcr_host, 0x100);
  fail:
@@ -734,6 +740,8 @@ static void mal_remove(struct platform_device *ofdev)
 
        mal_reset(mal);
 
+       free_netdev(mal->dummy_dev);
+
        dma_free_coherent(&ofdev->dev,
                          sizeof(struct mal_descriptor) *
                          (NUM_TX_BUFF * mal->num_tx_chans +
index d212373a72e7c86eeed1dbfea457994490c806f0..e0ddc41186a28bd627f58f8e6527b2ade7743090 100644 (file)
@@ -205,7 +205,7 @@ struct mal_instance {
        int                     index;
        spinlock_t              lock;
 
-       struct net_device       dummy_dev;
+       struct net_device       *dummy_dev;
 
        unsigned int features;
 };