]> www.infradead.org Git - users/hch/dma-mapping.git/commitdiff
fsl/fman: Save device references taken in mac_probe()
authorAleksandr Mishin <amishin@t-argos.ru>
Tue, 15 Oct 2024 06:01:21 +0000 (09:01 +0300)
committerPaolo Abeni <pabeni@redhat.com>
Mon, 21 Oct 2024 08:50:16 +0000 (10:50 +0200)
In mac_probe() there are calls to of_find_device_by_node() which takes
references to of_dev->dev. These references are not saved and not released
later on error path in mac_probe() and in mac_remove().

Add new fields into mac_device structure to save references taken for
future use in mac_probe() and mac_remove().

This is a preparation for further reference leaks fix.

Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/freescale/fman/mac.c
drivers/net/ethernet/freescale/fman/mac.h

index 9767586b4eb3298fbb76543a330263405821cb15..9b863db0bf0870352d373f474ead71822b2dcd31 100644 (file)
@@ -197,6 +197,7 @@ static int mac_probe(struct platform_device *_of_dev)
                err = -EINVAL;
                goto _return_of_node_put;
        }
+       mac_dev->fman_dev = &of_dev->dev;
 
        /* Get the FMan cell-index */
        err = of_property_read_u32(dev_node, "cell-index", &val);
@@ -208,7 +209,7 @@ static int mac_probe(struct platform_device *_of_dev)
        /* cell-index 0 => FMan id 1 */
        fman_id = (u8)(val + 1);
 
-       priv->fman = fman_bind(&of_dev->dev);
+       priv->fman = fman_bind(mac_dev->fman_dev);
        if (!priv->fman) {
                dev_err(dev, "fman_bind(%pOF) failed\n", dev_node);
                err = -ENODEV;
@@ -284,8 +285,9 @@ static int mac_probe(struct platform_device *_of_dev)
                        err = -EINVAL;
                        goto _return_of_node_put;
                }
+               mac_dev->fman_port_devs[i] = &of_dev->dev;
 
-               mac_dev->port[i] = fman_port_bind(&of_dev->dev);
+               mac_dev->port[i] = fman_port_bind(mac_dev->fman_port_devs[i]);
                if (!mac_dev->port[i]) {
                        dev_err(dev, "dev_get_drvdata(%pOF) failed\n",
                                dev_node);
index fe747915cc73792b66d8bfe4339894476fc841af..8b5b43d50f8efbaaeb3b1cec65068154f315eded 100644 (file)
 struct fman_mac;
 struct mac_priv_s;
 
+#define PORT_NUM 2
 struct mac_device {
        void __iomem            *vaddr;
        struct device           *dev;
        struct resource         *res;
        u8                       addr[ETH_ALEN];
-       struct fman_port        *port[2];
+       struct fman_port        *port[PORT_NUM];
        struct phylink          *phylink;
        struct phylink_config   phylink_config;
        phy_interface_t         phy_if;
@@ -52,6 +53,9 @@ struct mac_device {
 
        struct fman_mac         *fman_mac;
        struct mac_priv_s       *priv;
+
+       struct device           *fman_dev;
+       struct device           *fman_port_devs[PORT_NUM];
 };
 
 static inline struct mac_device