提交 df4f6e8c 编写于 作者: C Corentin Labbe 提交者: Thierry Reding

pwm: sunxi: Use of_device_get_match_data()

The usage of of_device_get_match_data reduce the code size a bit.
Furthermore, it prevents an improbable dereference when
of_match_device() returns NULL.
Signed-off-by: NCorentin Labbe <clabbe.montjoie@gmail.com>
Signed-off-by: NThierry Reding <thierry.reding@gmail.com>
上级 1b3d9a93
...@@ -368,14 +368,15 @@ static int sun4i_pwm_probe(struct platform_device *pdev) ...@@ -368,14 +368,15 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
struct sun4i_pwm_chip *pwm; struct sun4i_pwm_chip *pwm;
struct resource *res; struct resource *res;
int ret; int ret;
const struct of_device_id *match;
match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev);
pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
if (!pwm) if (!pwm)
return -ENOMEM; return -ENOMEM;
pwm->data = of_device_get_match_data(&pdev->dev);
if (!pwm->data)
return -ENODEV;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
pwm->base = devm_ioremap_resource(&pdev->dev, res); pwm->base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(pwm->base)) if (IS_ERR(pwm->base))
...@@ -385,7 +386,6 @@ static int sun4i_pwm_probe(struct platform_device *pdev) ...@@ -385,7 +386,6 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
if (IS_ERR(pwm->clk)) if (IS_ERR(pwm->clk))
return PTR_ERR(pwm->clk); return PTR_ERR(pwm->clk);
pwm->data = match->data;
pwm->chip.dev = &pdev->dev; pwm->chip.dev = &pdev->dev;
pwm->chip.ops = &sun4i_pwm_ops; pwm->chip.ops = &sun4i_pwm_ops;
pwm->chip.base = -1; pwm->chip.base = -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册