提交 92303c86 编写于 作者: D David S. Miller

Merge branch 'net-simplify-getting-driver_data'

Wolfram Sang says:

====================
net: simplify getting .driver_data

I got tired of fixing this in Renesas drivers manually, so I took the big
hammer. Remove this cumbersome code pattern which got copy-pasted too much
already:

-	struct platform_device *pdev = to_platform_device(dev);
-	struct ep93xx_keypad *keypad = platform_get_drvdata(pdev);
+	struct ep93xx_keypad *keypad = dev_get_drvdata(dev);

A branch, tested by buildbot, can be found here:

git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git coccinelle/get_drvdata

I have been asked if it couldn't be done for dev_set_drvdata as well. I checked
it and did not find one occasion where it could be simplified like this. Not
much of a surprise because driver_data is usually set in probe() functions
which access struct platform_device in many other ways.

I am open for other comments, suggestions, too, of course.

Here is the cocci-script I created:

@@
struct device* d;
identifier pdev;
expression *ptr;
@@
(
-	struct platform_device *pdev = to_platform_device(d);
|
-	struct platform_device *pdev;
	...
-	pdev = to_platform_device(d);
)
	<... when != pdev
-	&pdev->dev
+	d
	...>

	ptr =
-	platform_get_drvdata(pdev)
+	dev_get_drvdata(d)

	<... when != pdev
-	&pdev->dev
+	d
	...>
====================
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
...@@ -1190,16 +1190,14 @@ static void bcm_sf2_sw_shutdown(struct platform_device *pdev) ...@@ -1190,16 +1190,14 @@ static void bcm_sf2_sw_shutdown(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int bcm_sf2_suspend(struct device *dev) static int bcm_sf2_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct bcm_sf2_priv *priv = dev_get_drvdata(dev);
struct bcm_sf2_priv *priv = platform_get_drvdata(pdev);
return dsa_switch_suspend(priv->dev->ds); return dsa_switch_suspend(priv->dev->ds);
} }
static int bcm_sf2_resume(struct device *dev) static int bcm_sf2_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct bcm_sf2_priv *priv = dev_get_drvdata(dev);
struct bcm_sf2_priv *priv = platform_get_drvdata(pdev);
return dsa_switch_resume(priv->dev->ds); return dsa_switch_resume(priv->dev->ds);
} }
......
...@@ -955,8 +955,7 @@ qca8k_set_pm(struct qca8k_priv *priv, int enable) ...@@ -955,8 +955,7 @@ qca8k_set_pm(struct qca8k_priv *priv, int enable)
static int qca8k_suspend(struct device *dev) static int qca8k_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct qca8k_priv *priv = dev_get_drvdata(dev);
struct qca8k_priv *priv = platform_get_drvdata(pdev);
qca8k_set_pm(priv, 0); qca8k_set_pm(priv, 0);
...@@ -965,8 +964,7 @@ static int qca8k_suspend(struct device *dev) ...@@ -965,8 +964,7 @@ static int qca8k_suspend(struct device *dev)
static int qca8k_resume(struct device *dev) static int qca8k_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct qca8k_priv *priv = dev_get_drvdata(dev);
struct qca8k_priv *priv = platform_get_drvdata(pdev);
qca8k_set_pm(priv, 1); qca8k_set_pm(priv, 1);
......
...@@ -4156,8 +4156,7 @@ static int macb_remove(struct platform_device *pdev) ...@@ -4156,8 +4156,7 @@ static int macb_remove(struct platform_device *pdev)
static int __maybe_unused macb_suspend(struct device *dev) static int __maybe_unused macb_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct net_device *netdev = dev_get_drvdata(dev);
struct net_device *netdev = platform_get_drvdata(pdev);
struct macb *bp = netdev_priv(netdev); struct macb *bp = netdev_priv(netdev);
netif_carrier_off(netdev); netif_carrier_off(netdev);
...@@ -4179,8 +4178,7 @@ static int __maybe_unused macb_suspend(struct device *dev) ...@@ -4179,8 +4178,7 @@ static int __maybe_unused macb_suspend(struct device *dev)
static int __maybe_unused macb_resume(struct device *dev) static int __maybe_unused macb_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct net_device *netdev = dev_get_drvdata(dev);
struct net_device *netdev = platform_get_drvdata(pdev);
struct macb *bp = netdev_priv(netdev); struct macb *bp = netdev_priv(netdev);
if (bp->wol & MACB_WOL_ENABLED) { if (bp->wol & MACB_WOL_ENABLED) {
......
...@@ -1722,8 +1722,7 @@ dm9000_probe(struct platform_device *pdev) ...@@ -1722,8 +1722,7 @@ dm9000_probe(struct platform_device *pdev)
static int static int
dm9000_drv_suspend(struct device *dev) dm9000_drv_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct net_device *ndev = dev_get_drvdata(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct board_info *db; struct board_info *db;
if (ndev) { if (ndev) {
...@@ -1745,8 +1744,7 @@ dm9000_drv_suspend(struct device *dev) ...@@ -1745,8 +1744,7 @@ dm9000_drv_suspend(struct device *dev)
static int static int
dm9000_drv_resume(struct device *dev) dm9000_drv_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct net_device *ndev = dev_get_drvdata(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct board_info *db = netdev_priv(ndev); struct board_info *db = netdev_priv(ndev);
if (ndev) { if (ndev) {
......
...@@ -2447,8 +2447,7 @@ static int smc_drv_remove(struct platform_device *pdev) ...@@ -2447,8 +2447,7 @@ static int smc_drv_remove(struct platform_device *pdev)
static int smc_drv_suspend(struct device *dev) static int smc_drv_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct net_device *ndev = dev_get_drvdata(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
if (ndev) { if (ndev) {
if (netif_running(ndev)) { if (netif_running(ndev)) {
......
...@@ -3669,8 +3669,7 @@ static int cpsw_remove(struct platform_device *pdev) ...@@ -3669,8 +3669,7 @@ static int cpsw_remove(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int cpsw_suspend(struct device *dev) static int cpsw_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct net_device *ndev = dev_get_drvdata(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
if (cpsw->data.dual_emac) { if (cpsw->data.dual_emac) {
...@@ -3693,8 +3692,7 @@ static int cpsw_suspend(struct device *dev) ...@@ -3693,8 +3692,7 @@ static int cpsw_suspend(struct device *dev)
static int cpsw_resume(struct device *dev) static int cpsw_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct net_device *ndev = dev_get_drvdata(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
/* Select default pin state */ /* Select default pin state */
......
...@@ -2002,8 +2002,7 @@ static int davinci_emac_remove(struct platform_device *pdev) ...@@ -2002,8 +2002,7 @@ static int davinci_emac_remove(struct platform_device *pdev)
static int davinci_emac_suspend(struct device *dev) static int davinci_emac_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct net_device *ndev = dev_get_drvdata(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
if (netif_running(ndev)) if (netif_running(ndev))
emac_dev_stop(ndev); emac_dev_stop(ndev);
...@@ -2013,8 +2012,7 @@ static int davinci_emac_suspend(struct device *dev) ...@@ -2013,8 +2012,7 @@ static int davinci_emac_suspend(struct device *dev)
static int davinci_emac_resume(struct device *dev) static int davinci_emac_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct net_device *ndev = dev_get_drvdata(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
if (netif_running(ndev)) if (netif_running(ndev))
emac_dev_open(ndev); emac_dev_open(ndev);
......
...@@ -661,8 +661,7 @@ static int w5300_remove(struct platform_device *pdev) ...@@ -661,8 +661,7 @@ static int w5300_remove(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int w5300_suspend(struct device *dev) static int w5300_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct net_device *ndev = dev_get_drvdata(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct w5300_priv *priv = netdev_priv(ndev); struct w5300_priv *priv = netdev_priv(ndev);
if (netif_running(ndev)) { if (netif_running(ndev)) {
...@@ -676,8 +675,7 @@ static int w5300_suspend(struct device *dev) ...@@ -676,8 +675,7 @@ static int w5300_suspend(struct device *dev)
static int w5300_resume(struct device *dev) static int w5300_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct net_device *ndev = dev_get_drvdata(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct w5300_priv *priv = netdev_priv(ndev); struct w5300_priv *priv = netdev_priv(ndev);
if (!netif_running(ndev)) { if (!netif_running(ndev)) {
......
...@@ -289,8 +289,7 @@ static int mdio_mux_iproc_remove(struct platform_device *pdev) ...@@ -289,8 +289,7 @@ static int mdio_mux_iproc_remove(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int mdio_mux_iproc_suspend(struct device *dev) static int mdio_mux_iproc_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct iproc_mdiomux_desc *md = dev_get_drvdata(dev);
struct iproc_mdiomux_desc *md = platform_get_drvdata(pdev);
clk_disable_unprepare(md->core_clk); clk_disable_unprepare(md->core_clk);
...@@ -299,8 +298,7 @@ static int mdio_mux_iproc_suspend(struct device *dev) ...@@ -299,8 +298,7 @@ static int mdio_mux_iproc_suspend(struct device *dev)
static int mdio_mux_iproc_resume(struct device *dev) static int mdio_mux_iproc_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct iproc_mdiomux_desc *md = dev_get_drvdata(dev);
struct iproc_mdiomux_desc *md = platform_get_drvdata(pdev);
clk_prepare_enable(md->core_clk); clk_prepare_enable(md->core_clk);
mdio_mux_iproc_config(md); mdio_mux_iproc_config(md);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册