generic: rtl8366: introduce rtl8366_smi_alloc
authorGabor Juhos <juhosg@openwrt.org>
Thu, 15 Jul 2010 13:05:16 +0000 (13:05 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Thu, 15 Jul 2010 13:05:16 +0000 (13:05 +0000)
SVN-Revision: 22195

target/linux/generic/files/drivers/net/phy/rtl8366_smi.c
target/linux/generic/files/drivers/net/phy/rtl8366_smi.h
target/linux/generic/files/drivers/net/phy/rtl8366rb.c
target/linux/generic/files/drivers/net/phy/rtl8366s.c

index d0b3680562938c2ac84e9f2b23ba986b66380014..ac8862ced6fc1d27894669b2b01f2d1fac06c032 100644 (file)
@@ -741,13 +741,27 @@ static void rtl8366_smi_mii_cleanup(struct rtl8366_smi *smi)
        mdiobus_free(smi->mii_bus);
 }
 
+struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent)
+{
+       struct rtl8366_smi *smi;
+
+       BUG_ON(!parent);
+
+       smi = kzalloc(sizeof(*smi), GFP_KERNEL);
+       if (!smi) {
+               dev_err(parent, "no memory for private data\n");
+               return NULL;
+       }
+
+       smi->parent = parent;
+       return smi;
+}
+EXPORT_SYMBOL_GPL(rtl8366_smi_alloc);
+
 int rtl8366_smi_init(struct rtl8366_smi *smi)
 {
        int err;
 
-       if (!smi->parent)
-               return -EINVAL;
-
        if (!smi->ops)
                return -EINVAL;
 
index bd16cbe55e561db51615953ac7cd5af2da2e2fc0..775f95935e124211437fb825fa3d47cef54c7191 100644 (file)
@@ -87,6 +87,7 @@ struct rtl8366_smi_ops {
                                   int port, unsigned long long *val);
 };
 
+struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent);
 int rtl8366_smi_init(struct rtl8366_smi *smi);
 void rtl8366_smi_cleanup(struct rtl8366_smi *smi);
 int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data);
index 2156078f865292e070ba22944b4ff4e41c99c902..aa0b4a0b71d8bcc430b643b1505f8d25cab69de0 100644 (file)
@@ -1133,14 +1133,12 @@ static int __init rtl8366rb_probe(struct platform_device *pdev)
                goto err_out;
        }
 
-       smi = kzalloc(sizeof(*smi), GFP_KERNEL);
+       smi = rtl8366_smi_alloc(&pdev->dev);
        if (!smi) {
-               dev_err(&pdev->dev, "no memory for private data\n");
                err = -ENOMEM;
                goto err_out;
        }
 
-       smi->parent = &pdev->dev;
        smi->gpio_sda = pdata->gpio_sda;
        smi->gpio_sck = pdata->gpio_sck;
        smi->ops = &rtl8366rb_smi_ops;
index 923f51a9772205ad1af51b486a072fdaa10ebed9..6f3fdd5092e3454acc8b8a716acb6e8e0a631466 100644 (file)
@@ -1160,14 +1160,12 @@ static int __init rtl8366s_probe(struct platform_device *pdev)
                goto err_out;
        }
 
-       smi = kzalloc(sizeof(*smi), GFP_KERNEL);
+       smi = rtl8366_smi_alloc(&pdev->dev);
        if (!smi) {
-               dev_err(&pdev->dev, "no memory for private data\n");
                err = -ENOMEM;
                goto err_out;
        }
 
-       smi->parent = &pdev->dev;
        smi->gpio_sda = pdata->gpio_sda;
        smi->gpio_sck = pdata->gpio_sck;
        smi->ops = &rtl8366s_smi_ops;