On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut wrote:
>
> Allocate driver private data dynamically in its init function and drop
> the static driver private data variable. Pass the dynamic private data
> throughout the driver. This is done in preparation for DM conversion.
>
> Signed-off-by: Marek Vasut
> Cc: Joe Hershberger
> Cc: Ramon Fried
> ---
> drivers/net/dm9000x.c | 24 +---
> 1 file changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 7e1368a1be9..666883ee19e 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -77,8 +77,6 @@ struct dm9000_priv {
> struct eth_device netdev;
> };
>
> -static struct dm9000_priv dm9000_info;
> -
> /* DM9000 network board routine */
> #ifndef CONFIG_DM9000_BYTE_SWAPPED
> #define dm9000_outb(d, r) writeb((d), (r))
> @@ -313,9 +311,9 @@ dm9000_reset(void)
> /* Initialize dm9000 board */
> static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
> {
> + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> int i, oft, lnk;
> u8 io_mode;
> - struct dm9000_priv *db = &dm9000_info;
>
> /* RESET device */
> dm9000_reset();
> @@ -430,10 +428,10 @@ static int dm9000_init(struct eth_device *dev, struct
> bd_info *bd)
> * Hardware start transmission.
> * Send a packet to media from the upper layer.
> */
> -static int dm9000_send(struct eth_device *netdev, void *packet, int length)
> +static int dm9000_send(struct eth_device *dev, void *packet, int length)
> {
> + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> int tmo;
> - struct dm9000_priv *db = &dm9000_info;
>
> dm9000_dump_packet(__func__, packet, length);
>
> @@ -483,12 +481,12 @@ static void dm9000_halt(struct eth_device *netdev)
> /*
> * Received a packet and pass to upper layer
> */
> -static int dm9000_rx(struct eth_device *netdev)
> +static int dm9000_rx(struct eth_device *dev)
> {
> + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> u8 rxbyte;
> u8 *rdptr = (u8 *)net_rx_packets[0];
> u16 rxstatus, rxlen = 0;
> - struct dm9000_priv *db = &dm9000_info;
>
> /*
> * Check packet ready or not, we must check
> @@ -591,18 +589,22 @@ static void dm9000_get_enetaddr(struct eth_device *dev)
> {}
>
> int dm9000_initialize(struct bd_info *bis)
> {
> - struct eth_device *dev = &dm9000_info.netdev;
> + struct dm9000_priv *priv;
> +
> + priv = kcalloc(1, sizeof(*priv));
> + if (!priv)
> + return -ENOMEM;
>
> /* Load MAC address from EEPROM */
> - dm9000_get_enetaddr(dev);
> + dm9000_get_enetaddr(&priv->dev);
>
> dev->init = dm9000_init;
> dev->halt = dm9000_halt;
> dev->send = dm9000_send;
> dev->recv = dm9000_rx;
> - strcpy(dev->name, "dm9000");
> + strcpy(&priv->dev.name, "dm9000");
>
> - eth_register(dev);
> + eth_register(&priv->dev);
>
> return 0;
> }
> --
> 2.35.1
>
Reviewed-by: Ramon Fried