summaryrefslogtreecommitdiff
path: root/drivers/pwm/pwm-dwc.c
diff options
context:
space:
mode:
authorBen Dooks <ben.dooks@sifive.com>2022-12-23 18:38:14 +0300
committerThierry Reding <thierry.reding@gmail.com>2023-02-20 14:26:34 +0300
commita357d1493f0c66ce8006dd28c07646d1f891259a (patch)
treef34be6c8eebf847fa9abb48b28e0b7f412f4e791 /drivers/pwm/pwm-dwc.c
parentf7c843d6d7f82d26ee9efe689f9b3208dbf7ed87 (diff)
downloadlinux-a357d1493f0c66ce8006dd28c07646d1f891259a.tar.xz
pwm: dwc: Move memory allocation to own function
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>
Diffstat (limited to 'drivers/pwm/pwm-dwc.c')
-rw-r--r--drivers/pwm/pwm-dwc.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/drivers/pwm/pwm-dwc.c b/drivers/pwm/pwm-dwc.c
index de1c497d5b48..e9399df702ed 100644
--- a/drivers/pwm/pwm-dwc.c
+++ b/drivers/pwm/pwm-dwc.c
@@ -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;
@@ -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;