Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pwm: constify pwm_ops structures

Declare pwm_ops structures as const as they are only stored in the ops
field of a pwm_chip structure. This field is of type const struct pwm_ops
*, so pwm_ops structures having this property can be declared as const.
Done using Coccinelle:

@r1 disable optional_qualifier@
identifier i;
position p;
@@
static struct pwm_ops i@p={...};

@ok1@
identifier r1.i;
position p;
struct pxa_pwm_chip pwm;
struct bfin_pwm_chip bwm;
struct vt8500_chip vp;
struct imx_chip icp;
@@
(
pwm.chip.ops=&i@p
|
bwm.chip.ops=&i@p
|
vp.chip.ops=&i@p
|
icp.chip.ops=&i@p
)

@bad@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
struct pwm_ops i;

File size details:

text data bss dec hex filename
1646 328 0 1974 7b6 drivers/pwm/pwm-imx.o
1742 224 0 1966 7ae drivers/pwm/pwm-imx.o

1941 296 0 2237 8bd drivers/pwm/pwm-pxa.o
2037 192 0 2229 8b5 drivers/pwm/pwm-pxa.o

1946 296 0 2242 8c2 drivers/pwm/pwm-vt8500.o
2050 192 0 2242 8c2 drivers/pwm/pwm-vt8500.o

The drivers/pwm/pwm-bfin.o file did not compile.

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Bhumika Goyal and committed by
Thierry Reding
b2ec9efc 5bf22ff3

+4 -4
+1 -1
drivers/pwm/pwm-bfin.c
··· 103 103 disable_gptimer(priv->pin); 104 104 } 105 105 106 - static struct pwm_ops bfin_pwm_ops = { 106 + static const struct pwm_ops bfin_pwm_ops = { 107 107 .request = bfin_pwm_request, 108 108 .free = bfin_pwm_free, 109 109 .config = bfin_pwm_config,
+1 -1
drivers/pwm/pwm-imx.c
··· 240 240 clk_disable_unprepare(imx->clk_per); 241 241 } 242 242 243 - static struct pwm_ops imx_pwm_ops = { 243 + static const struct pwm_ops imx_pwm_ops = { 244 244 .enable = imx_pwm_enable, 245 245 .disable = imx_pwm_disable, 246 246 .config = imx_pwm_config,
+1 -1
drivers/pwm/pwm-pxa.c
··· 118 118 clk_disable_unprepare(pc->clk); 119 119 } 120 120 121 - static struct pwm_ops pxa_pwm_ops = { 121 + static const struct pwm_ops pxa_pwm_ops = { 122 122 .config = pxa_pwm_config, 123 123 .enable = pxa_pwm_enable, 124 124 .disable = pxa_pwm_disable,
+1 -1
drivers/pwm/pwm-vt8500.c
··· 184 184 return 0; 185 185 } 186 186 187 - static struct pwm_ops vt8500_pwm_ops = { 187 + static const struct pwm_ops vt8500_pwm_ops = { 188 188 .enable = vt8500_pwm_enable, 189 189 .disable = vt8500_pwm_disable, 190 190 .config = vt8500_pwm_config,