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

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>

authored by

Stephen Warren and committed by
Linus Walleij
d26bc49f 22f099d0

+21 -4
+21 -4
drivers/pinctrl/core.c
··· 908 908 const struct pinctrl_ops *ops = pctldev->desc->pctlops; 909 909 unsigned selector = 0; 910 910 911 - /* No grouping */ 912 - if (!ops) 913 - return 0; 914 - 915 911 mutex_lock(&pinctrl_mutex); 916 912 917 913 seq_puts(s, "registered pin groups:\n"); ··· 1221 1225 1222 1226 #endif 1223 1227 1228 + static int pinctrl_check_ops(struct pinctrl_dev *pctldev) 1229 + { 1230 + const struct pinctrl_ops *ops = pctldev->desc->pctlops; 1231 + 1232 + if (!ops || 1233 + !ops->list_groups || 1234 + !ops->get_group_name || 1235 + !ops->get_group_pins) 1236 + return -EINVAL; 1237 + 1238 + return 0; 1239 + } 1240 + 1224 1241 /** 1225 1242 * pinctrl_register() - register a pin controller device 1226 1243 * @pctldesc: descriptor for this pin controller ··· 1264 1255 INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL); 1265 1256 INIT_LIST_HEAD(&pctldev->gpio_ranges); 1266 1257 pctldev->dev = dev; 1258 + 1259 + /* check core ops for sanity */ 1260 + ret = pinctrl_check_ops(pctldev); 1261 + if (ret) { 1262 + pr_err("%s pinctrl ops lacks necessary functions\n", 1263 + pctldesc->name); 1264 + goto out_err; 1265 + } 1267 1266 1268 1267 /* If we're implementing pinmuxing, check the ops for sanity */ 1269 1268 if (pctldesc->pmxops) {