Skip to content

Commit

Permalink
pwm: sunxi: Use of_device_get_match_data()
Browse files Browse the repository at this point in the history
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: Corentin Labbe <[email protected]>
Signed-off-by: Thierry Reding <[email protected]>
  • Loading branch information
montjoie authored and thierryreding committed Nov 15, 2017
1 parent 1b3d9a9 commit df4f6e8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/pwm/pwm-sun4i.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,15 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
struct sun4i_pwm_chip *pwm;
struct resource *res;
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);
if (!pwm)
return -ENOMEM;

pwm->data = of_device_get_match_data(&pdev->dev);
if (!pwm->data)
return -ENODEV;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
pwm->base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(pwm->base))
Expand All @@ -385,7 +386,6 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
if (IS_ERR(pwm->clk))
return PTR_ERR(pwm->clk);

pwm->data = match->data;
pwm->chip.dev = &pdev->dev;
pwm->chip.ops = &sun4i_pwm_ops;
pwm->chip.base = -1;
Expand Down

0 comments on commit df4f6e8

Please sign in to comment.