Skip to content

Commit

Permalink
pwm: Manage owner assignment implicitly for drivers
Browse files Browse the repository at this point in the history
Instead of requiring each driver to care for assigning the owner member
of struct pwm_ops, handle that implicitly using a macro. Note that the
owner member has to be moved to struct pwm_chip, as the ops structure
usually lives in read-only memory and so cannot be modified.

The upside is that new low level drivers cannot forget the assignment and
save one line each. The pwm-crc driver didn't assign .owner, that's not
a problem in practice though as the driver cannot be compiled as a
module.

Acked-by: Andy Shevchenko <[email protected]> # Intel LPSS
Reviewed-by: Florian Fainelli <[email protected]> # pwm-{bcm,brcm}*.c
Acked-by: Jernej Skrabec <[email protected]> # sun4i
Acked-by: Andi Shyti <[email protected]>
Acked-by: Nobuhiro Iwamatsu <[email protected]> # pwm-visconti
Acked-by: Heiko Stuebner <[email protected]> # pwm-rockchip
Acked-by: Michael Walle <[email protected]> # pwm-sl28cpld
Acked-by: Neil Armstrong <[email protected]> # pwm-meson
Reviewed-by: Linus Walleij <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Uwe Kleine-König <[email protected]>
Signed-off-by: Thierry Reding <[email protected]>
  • Loading branch information
Uwe Kleine-König authored and thierryreding committed Oct 13, 2023
1 parent 7a3663c commit 384461a
Show file tree
Hide file tree
Showing 68 changed files with 20 additions and 82 deletions.
1 change: 0 additions & 1 deletion drivers/gpio/gpio-mvebu.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,6 @@ static const struct pwm_ops mvebu_pwm_ops = {
.free = mvebu_pwm_free,
.get_state = mvebu_pwm_get_state,
.apply = mvebu_pwm_apply,
.owner = THIS_MODULE,
};

static void __maybe_unused mvebu_pwm_suspend(struct mvebu_gpio_chip *mvchip)
Expand Down
1 change: 0 additions & 1 deletion drivers/gpu/drm/bridge/ti-sn65dsi86.c
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,6 @@ static const struct pwm_ops ti_sn_pwm_ops = {
.free = ti_sn_pwm_free,
.apply = ti_sn_pwm_apply,
.get_state = ti_sn_pwm_get_state,
.owner = THIS_MODULE,
};

static int ti_sn_pwm_probe(struct auxiliary_device *adev,
Expand Down
1 change: 0 additions & 1 deletion drivers/leds/rgb/leds-qcom-lpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,6 @@ static const struct pwm_ops lpg_pwm_ops = {
.request = lpg_pwm_request,
.apply = lpg_pwm_apply,
.get_state = lpg_pwm_get_state,
.owner = THIS_MODULE,
};

static int lpg_add_pwm(struct lpg *lpg)
Expand Down
24 changes: 14 additions & 10 deletions drivers/pwm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
if (test_bit(PWMF_REQUESTED, &pwm->flags))
return -EBUSY;

if (!try_module_get(pwm->chip->ops->owner))
if (!try_module_get(pwm->chip->owner))
return -ENODEV;

if (pwm->chip->ops->request) {
err = pwm->chip->ops->request(pwm->chip, pwm);
if (err) {
module_put(pwm->chip->ops->owner);
module_put(pwm->chip->owner);
return err;
}
}
Expand Down Expand Up @@ -253,14 +253,16 @@ static bool pwm_ops_check(const struct pwm_chip *chip)
}

/**
* pwmchip_add() - register a new PWM chip
* __pwmchip_add() - register a new PWM chip
* @chip: the PWM chip to add
* @owner: reference to the module providing the chip.
*
* Register a new PWM chip.
* Register a new PWM chip. @owner is supposed to be THIS_MODULE, use the
* pwmchip_add wrapper to do this right.
*
* Returns: 0 on success or a negative error code on failure.
*/
int pwmchip_add(struct pwm_chip *chip)
int __pwmchip_add(struct pwm_chip *chip, struct module *owner)
{
struct pwm_device *pwm;
unsigned int i;
Expand All @@ -272,6 +274,8 @@ int pwmchip_add(struct pwm_chip *chip)
if (!pwm_ops_check(chip))
return -EINVAL;

chip->owner = owner;

chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL);
if (!chip->pwms)
return -ENOMEM;
Expand Down Expand Up @@ -306,7 +310,7 @@ int pwmchip_add(struct pwm_chip *chip)

return 0;
}
EXPORT_SYMBOL_GPL(pwmchip_add);
EXPORT_SYMBOL_GPL(__pwmchip_add);

/**
* pwmchip_remove() - remove a PWM chip
Expand Down Expand Up @@ -338,17 +342,17 @@ static void devm_pwmchip_remove(void *data)
pwmchip_remove(chip);
}

int devm_pwmchip_add(struct device *dev, struct pwm_chip *chip)
int __devm_pwmchip_add(struct device *dev, struct pwm_chip *chip, struct module *owner)
{
int ret;

ret = pwmchip_add(chip);
ret = __pwmchip_add(chip, owner);
if (ret)
return ret;

return devm_add_action_or_reset(dev, devm_pwmchip_remove, chip);
}
EXPORT_SYMBOL_GPL(devm_pwmchip_add);
EXPORT_SYMBOL_GPL(__devm_pwmchip_add);

/**
* pwm_request_from_chip() - request a PWM device relative to a PWM chip
Expand Down Expand Up @@ -979,7 +983,7 @@ void pwm_put(struct pwm_device *pwm)
pwm_set_chip_data(pwm, NULL);
pwm->label = NULL;

module_put(pwm->chip->ops->owner);
module_put(pwm->chip->owner);
out:
mutex_unlock(&pwm_lock);
}
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-ab8500.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ static int ab8500_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
static const struct pwm_ops ab8500_pwm_ops = {
.apply = ab8500_pwm_apply,
.get_state = ab8500_pwm_get_state,
.owner = THIS_MODULE,
};

static int ab8500_pwm_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ static int apple_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
static const struct pwm_ops apple_pwm_ops = {
.apply = apple_pwm_apply,
.get_state = apple_pwm_get_state,
.owner = THIS_MODULE,
};

static int apple_pwm_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-atmel-hlcdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ static int atmel_hlcdc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,

static const struct pwm_ops atmel_hlcdc_pwm_ops = {
.apply = atmel_hlcdc_pwm_apply,
.owner = THIS_MODULE,
};

static const struct atmel_hlcdc_pwm_errata atmel_hlcdc_pwm_at91sam9x5_errata = {
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-atmel-tcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ static const struct pwm_ops atmel_tcb_pwm_ops = {
.request = atmel_tcb_pwm_request,
.free = atmel_tcb_pwm_free,
.apply = atmel_tcb_pwm_apply,
.owner = THIS_MODULE,
};

static struct atmel_tcb_config tcb_rm9200_config = {
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-atmel.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ static int atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
static const struct pwm_ops atmel_pwm_ops = {
.apply = atmel_pwm_apply,
.get_state = atmel_pwm_get_state,
.owner = THIS_MODULE,
};

static const struct atmel_pwm_data atmel_sam9rl_pwm_data = {
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-bcm-iproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm,
static const struct pwm_ops iproc_pwm_ops = {
.apply = iproc_pwmc_apply,
.get_state = iproc_pwmc_get_state,
.owner = THIS_MODULE,
};

static int iproc_pwmc_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-bcm-kona.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ static int kona_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm,

static const struct pwm_ops kona_pwm_ops = {
.apply = kona_pwmc_apply,
.owner = THIS_MODULE,
};

static int kona_pwmc_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-bcm2835.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ static const struct pwm_ops bcm2835_pwm_ops = {
.request = bcm2835_pwm_request,
.free = bcm2835_pwm_free,
.apply = bcm2835_pwm_apply,
.owner = THIS_MODULE,
};

static int bcm2835_pwm_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-berlin.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ static const struct pwm_ops berlin_pwm_ops = {
.request = berlin_pwm_request,
.free = berlin_pwm_free,
.apply = berlin_pwm_apply,
.owner = THIS_MODULE,
};

static const struct of_device_id berlin_pwm_match[] = {
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-brcmstb.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ static int brcmstb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,

static const struct pwm_ops brcmstb_pwm_ops = {
.apply = brcmstb_pwm_apply,
.owner = THIS_MODULE,
};

static const struct of_device_id brcmstb_pwm_of_match[] = {
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ static int pwm_clk_apply(struct pwm_chip *chip, struct pwm_device *pwm,

static const struct pwm_ops pwm_clk_ops = {
.apply = pwm_clk_apply,
.owner = THIS_MODULE,
};

static int pwm_clk_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-clps711x.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ static int clps711x_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
static const struct pwm_ops clps711x_pwm_ops = {
.request = clps711x_pwm_request,
.apply = clps711x_pwm_apply,
.owner = THIS_MODULE,
};

static struct pwm_device *clps711x_pwm_xlate(struct pwm_chip *chip,
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-cros-ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ static const struct pwm_ops cros_ec_pwm_ops = {
.free = cros_ec_pwm_free,
.get_state = cros_ec_pwm_get_state,
.apply = cros_ec_pwm_apply,
.owner = THIS_MODULE,
};

/*
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-dwc.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ static int dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
static const struct pwm_ops dwc_pwm_ops = {
.apply = dwc_pwm_apply,
.get_state = dwc_pwm_get_state,
.owner = THIS_MODULE,
};

static struct dwc_pwm *dwc_pwm_alloc(struct device *dev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-ep93xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ static const struct pwm_ops ep93xx_pwm_ops = {
.request = ep93xx_pwm_request,
.free = ep93xx_pwm_free,
.apply = ep93xx_pwm_apply,
.owner = THIS_MODULE,
};

static int ep93xx_pwm_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-fsl-ftm.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ static const struct pwm_ops fsl_pwm_ops = {
.request = fsl_pwm_request,
.free = fsl_pwm_free,
.apply = fsl_pwm_apply,
.owner = THIS_MODULE,
};

static int fsl_pwm_init(struct fsl_pwm_chip *fpc)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-hibvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ static const struct pwm_ops hibvt_pwm_ops = {
.get_state = hibvt_pwm_get_state,
.apply = hibvt_pwm_apply,

.owner = THIS_MODULE,
};

static int hibvt_pwm_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-img.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ static int img_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,

static const struct pwm_ops img_pwm_ops = {
.apply = img_pwm_apply,
.owner = THIS_MODULE,
};

static const struct img_pwm_soc_data pistachio_pwm = {
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-imx-tpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ static const struct pwm_ops imx_tpm_pwm_ops = {
.free = pwm_imx_tpm_free,
.get_state = pwm_imx_tpm_get_state,
.apply = pwm_imx_tpm_apply,
.owner = THIS_MODULE,
};

static int pwm_imx_tpm_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-imx1.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ static int pwm_imx1_apply(struct pwm_chip *chip, struct pwm_device *pwm,

static const struct pwm_ops pwm_imx1_ops = {
.apply = pwm_imx1_apply,
.owner = THIS_MODULE,
};

static const struct of_device_id pwm_imx1_dt_ids[] = {
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-imx27.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm,
static const struct pwm_ops pwm_imx27_ops = {
.apply = pwm_imx27_apply,
.get_state = pwm_imx27_get_state,
.owner = THIS_MODULE,
};

static const struct of_device_id pwm_imx27_dt_ids[] = {
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-intel-lgm.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ static int lgm_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
static const struct pwm_ops lgm_pwm_ops = {
.get_state = lgm_pwm_get_state,
.apply = lgm_pwm_apply,
.owner = THIS_MODULE,
};

static void lgm_pwm_init(struct lgm_pwm_chip *pc)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-iqs620a.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ static int iqs620_pwm_notifier(struct notifier_block *notifier,
static const struct pwm_ops iqs620_pwm_ops = {
.apply = iqs620_pwm_apply,
.get_state = iqs620_pwm_get_state,
.owner = THIS_MODULE,
};

static void iqs620_pwm_notifier_unregister(void *context)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-jz4740.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ static const struct pwm_ops jz4740_pwm_ops = {
.request = jz4740_pwm_request,
.free = jz4740_pwm_free,
.apply = jz4740_pwm_apply,
.owner = THIS_MODULE,
};

static int jz4740_pwm_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-keembay.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ static int keembay_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
}

static const struct pwm_ops keembay_pwm_ops = {
.owner = THIS_MODULE,
.apply = keembay_pwm_apply,
.get_state = keembay_pwm_get_state,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-lp3943.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ static const struct pwm_ops lp3943_pwm_ops = {
.request = lp3943_pwm_request,
.free = lp3943_pwm_free,
.apply = lp3943_pwm_apply,
.owner = THIS_MODULE,
};

static int lp3943_pwm_parse_dt(struct device *dev,
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-lpc18xx-sct.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ static const struct pwm_ops lpc18xx_pwm_ops = {
.apply = lpc18xx_pwm_apply,
.request = lpc18xx_pwm_request,
.free = lpc18xx_pwm_free,
.owner = THIS_MODULE,
};

static const struct of_device_id lpc18xx_pwm_of_match[] = {
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-lpc32xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ static int lpc32xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,

static const struct pwm_ops lpc32xx_pwm_ops = {
.apply = lpc32xx_pwm_apply,
.owner = THIS_MODULE,
};

static int lpc32xx_pwm_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-lpss.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ static int pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
static const struct pwm_ops pwm_lpss_ops = {
.apply = pwm_lpss_apply,
.get_state = pwm_lpss_get_state,
.owner = THIS_MODULE,
};

struct pwm_lpss_chip *devm_pwm_lpss_probe(struct device *dev, void __iomem *base,
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-mediatek.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,

static const struct pwm_ops pwm_mediatek_ops = {
.apply = pwm_mediatek_apply,
.owner = THIS_MODULE,
};

static int pwm_mediatek_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-meson.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ static const struct pwm_ops meson_pwm_ops = {
.free = meson_pwm_free,
.apply = meson_pwm_apply,
.get_state = meson_pwm_get_state,
.owner = THIS_MODULE,
};

static const char * const pwm_meson8b_parent_names[] = {
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-microchip-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ static int mchp_core_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm
static const struct pwm_ops mchp_core_pwm_ops = {
.apply = mchp_core_pwm_apply,
.get_state = mchp_core_pwm_get_state,
.owner = THIS_MODULE,
};

static const struct of_device_id mchp_core_of_match[] = {
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-mtk-disp.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ static int mtk_disp_pwm_get_state(struct pwm_chip *chip,
static const struct pwm_ops mtk_disp_pwm_ops = {
.apply = mtk_disp_pwm_apply,
.get_state = mtk_disp_pwm_get_state,
.owner = THIS_MODULE,
};

static int mtk_disp_pwm_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-mxs.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,

static const struct pwm_ops mxs_pwm_ops = {
.apply = mxs_pwm_apply,
.owner = THIS_MODULE,
};

static int mxs_pwm_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-ntxec.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ static int ntxec_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm_dev,
}

static const struct pwm_ops ntxec_pwm_ops = {
.owner = THIS_MODULE,
.apply = ntxec_pwm_apply,
/*
* No .get_state callback, because the current state cannot be read
Expand Down
1 change: 0 additions & 1 deletion drivers/pwm/pwm-omap-dmtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ static int pwm_omap_dmtimer_apply(struct pwm_chip *chip,

static const struct pwm_ops pwm_omap_dmtimer_ops = {
.apply = pwm_omap_dmtimer_apply,
.owner = THIS_MODULE,
};

static int pwm_omap_dmtimer_probe(struct platform_device *pdev)
Expand Down
Loading

0 comments on commit 384461a

Please sign in to comment.