Skip to content

Commit

Permalink
pwm: dwc: Move memory allocation to own function
Browse files Browse the repository at this point in the history
In preparation for adding other bus support, move the allocation
of the PWM structure out of the main driver code.

Signed-off-by: Ben Dooks <ben.dooks@sifive.com>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
  • Loading branch information
Ben Dooks authored and Thierry Reding committed Feb 20, 2023
1 parent f7c843d commit a357d14
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions drivers/pwm/pwm-dwc.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,29 @@ static const struct pwm_ops dwc_pwm_ops = {
.owner = THIS_MODULE,
};

static struct dwc_pwm *dwc_pwm_alloc(struct device *dev)
{
struct dwc_pwm *dwc;

dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
if (!dwc)
return NULL;

dwc->chip.dev = dev;
dwc->chip.ops = &dwc_pwm_ops;
dwc->chip.npwm = DWC_TIMERS_TOTAL;

dev_set_drvdata(dev, dwc);
return dwc;
}

static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)
{
struct device *dev = &pci->dev;
struct dwc_pwm *dwc;
int ret;

dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
dwc = dwc_pwm_alloc(dev);
if (!dwc)
return -ENOMEM;

Expand All @@ -228,12 +244,6 @@ static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)
return -ENOMEM;
}

pci_set_drvdata(pci, dwc);

dwc->chip.dev = dev;
dwc->chip.ops = &dwc_pwm_ops;
dwc->chip.npwm = DWC_TIMERS_TOTAL;

ret = pwmchip_add(&dwc->chip);
if (ret)
return ret;
Expand Down

0 comments on commit a357d14

Please sign in to comment.