Skip to content

Commit

Permalink
Merge branch 'net-simplify-getting-driver_data'
Browse files Browse the repository at this point in the history
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: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Oct 22, 2018
2 parents 21ea1d3 + 2c67e33 commit 92303c8
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 34 deletions.
6 changes: 2 additions & 4 deletions drivers/net/dsa/bcm_sf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,16 +1190,14 @@ static void bcm_sf2_sw_shutdown(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP
static int bcm_sf2_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct bcm_sf2_priv *priv = platform_get_drvdata(pdev);
struct bcm_sf2_priv *priv = dev_get_drvdata(dev);

return dsa_switch_suspend(priv->dev->ds);
}

static int bcm_sf2_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct bcm_sf2_priv *priv = platform_get_drvdata(pdev);
struct bcm_sf2_priv *priv = dev_get_drvdata(dev);

return dsa_switch_resume(priv->dev->ds);
}
Expand Down
6 changes: 2 additions & 4 deletions drivers/net/dsa/qca8k.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,7 @@ qca8k_set_pm(struct qca8k_priv *priv, int enable)

static int qca8k_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct qca8k_priv *priv = platform_get_drvdata(pdev);
struct qca8k_priv *priv = dev_get_drvdata(dev);

qca8k_set_pm(priv, 0);

Expand All @@ -965,8 +964,7 @@ static int qca8k_suspend(struct device *dev)

static int qca8k_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct qca8k_priv *priv = platform_get_drvdata(pdev);
struct qca8k_priv *priv = dev_get_drvdata(dev);

qca8k_set_pm(priv, 1);

Expand Down
6 changes: 2 additions & 4 deletions drivers/net/ethernet/cadence/macb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4156,8 +4156,7 @@ static int macb_remove(struct platform_device *pdev)

static int __maybe_unused macb_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *netdev = platform_get_drvdata(pdev);
struct net_device *netdev = dev_get_drvdata(dev);
struct macb *bp = netdev_priv(netdev);

netif_carrier_off(netdev);
Expand All @@ -4179,8 +4178,7 @@ static int __maybe_unused macb_suspend(struct device *dev)

static int __maybe_unused macb_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *netdev = platform_get_drvdata(pdev);
struct net_device *netdev = dev_get_drvdata(dev);
struct macb *bp = netdev_priv(netdev);

if (bp->wol & MACB_WOL_ENABLED) {
Expand Down
6 changes: 2 additions & 4 deletions drivers/net/ethernet/davicom/dm9000.c
Original file line number Diff line number Diff line change
Expand Up @@ -1722,8 +1722,7 @@ dm9000_probe(struct platform_device *pdev)
static int
dm9000_drv_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct net_device *ndev = dev_get_drvdata(dev);
struct board_info *db;

if (ndev) {
Expand All @@ -1745,8 +1744,7 @@ dm9000_drv_suspend(struct device *dev)
static int
dm9000_drv_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct net_device *ndev = dev_get_drvdata(dev);
struct board_info *db = netdev_priv(ndev);

if (ndev) {
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/ethernet/smsc/smc91x.c
Original file line number Diff line number Diff line change
Expand Up @@ -2447,8 +2447,7 @@ static int smc_drv_remove(struct platform_device *pdev)

static int smc_drv_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct net_device *ndev = dev_get_drvdata(dev);

if (ndev) {
if (netif_running(ndev)) {
Expand Down
6 changes: 2 additions & 4 deletions drivers/net/ethernet/ti/cpsw.c
Original file line number Diff line number Diff line change
Expand Up @@ -3669,8 +3669,7 @@ static int cpsw_remove(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP
static int cpsw_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct net_device *ndev = dev_get_drvdata(dev);
struct cpsw_common *cpsw = ndev_to_cpsw(ndev);

if (cpsw->data.dual_emac) {
Expand All @@ -3693,8 +3692,7 @@ static int cpsw_suspend(struct device *dev)

static int cpsw_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct net_device *ndev = dev_get_drvdata(dev);
struct cpsw_common *cpsw = ndev_to_cpsw(ndev);

/* Select default pin state */
Expand Down
6 changes: 2 additions & 4 deletions drivers/net/ethernet/ti/davinci_emac.c
Original file line number Diff line number Diff line change
Expand Up @@ -2002,8 +2002,7 @@ static int davinci_emac_remove(struct platform_device *pdev)

static int davinci_emac_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct net_device *ndev = dev_get_drvdata(dev);

if (netif_running(ndev))
emac_dev_stop(ndev);
Expand All @@ -2013,8 +2012,7 @@ static int davinci_emac_suspend(struct device *dev)

static int davinci_emac_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct net_device *ndev = dev_get_drvdata(dev);

if (netif_running(ndev))
emac_dev_open(ndev);
Expand Down
6 changes: 2 additions & 4 deletions drivers/net/ethernet/wiznet/w5300.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,7 @@ static int w5300_remove(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP
static int w5300_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct net_device *ndev = dev_get_drvdata(dev);
struct w5300_priv *priv = netdev_priv(ndev);

if (netif_running(ndev)) {
Expand All @@ -676,8 +675,7 @@ static int w5300_suspend(struct device *dev)

static int w5300_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
struct net_device *ndev = dev_get_drvdata(dev);
struct w5300_priv *priv = netdev_priv(ndev);

if (!netif_running(ndev)) {
Expand Down
6 changes: 2 additions & 4 deletions drivers/net/phy/mdio-mux-bcm-iproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ static int mdio_mux_iproc_remove(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP
static int mdio_mux_iproc_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct iproc_mdiomux_desc *md = platform_get_drvdata(pdev);
struct iproc_mdiomux_desc *md = dev_get_drvdata(dev);

clk_disable_unprepare(md->core_clk);

Expand All @@ -299,8 +298,7 @@ static int mdio_mux_iproc_suspend(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 = platform_get_drvdata(pdev);
struct iproc_mdiomux_desc *md = dev_get_drvdata(dev);

clk_prepare_enable(md->core_clk);
mdio_mux_iproc_config(md);
Expand Down

0 comments on commit 92303c8

Please sign in to comment.