Skip to content

Commit d26bc49

Browse files
swarrenLinus Walleij
authored andcommitted
pinctrl: implement pinctrl_check_ops
Most code assumes that the pinctrl ops are present. Validate this when registering a pinctrl driver. Remove the one place in the code that was checking whether one of these non-optional ops was present. Signed-off-by: Stephen Warren <swarren@wwwdotorg.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 22f099d commit d26bc49

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

drivers/pinctrl/core.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,6 @@ static int pinctrl_groups_show(struct seq_file *s, void *what)
908908
const struct pinctrl_ops *ops = pctldev->desc->pctlops;
909909
unsigned selector = 0;
910910

911-
/* No grouping */
912-
if (!ops)
913-
return 0;
914-
915911
mutex_lock(&pinctrl_mutex);
916912

917913
seq_puts(s, "registered pin groups:\n");
@@ -1225,6 +1221,19 @@ static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
12251221

12261222
#endif
12271223

1224+
static int pinctrl_check_ops(struct pinctrl_dev *pctldev)
1225+
{
1226+
const struct pinctrl_ops *ops = pctldev->desc->pctlops;
1227+
1228+
if (!ops ||
1229+
!ops->list_groups ||
1230+
!ops->get_group_name ||
1231+
!ops->get_group_pins)
1232+
return -EINVAL;
1233+
1234+
return 0;
1235+
}
1236+
12281237
/**
12291238
* pinctrl_register() - register a pin controller device
12301239
* @pctldesc: descriptor for this pin controller
@@ -1256,6 +1265,14 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
12561265
INIT_LIST_HEAD(&pctldev->gpio_ranges);
12571266
pctldev->dev = dev;
12581267

1268+
/* check core ops for sanity */
1269+
ret = pinctrl_check_ops(pctldev);
1270+
if (ret) {
1271+
pr_err("%s pinctrl ops lacks necessary functions\n",
1272+
pctldesc->name);
1273+
goto out_err;
1274+
}
1275+
12591276
/* If we're implementing pinmuxing, check the ops for sanity */
12601277
if (pctldesc->pmxops) {
12611278
ret = pinmux_check_ops(pctldev);

0 commit comments

Comments
 (0)