Currently only the drivers/pinctrl/devicetree.c code allows registering pinctrl-mappings which may later be unregistered, all other mappings are assumed to be permanent. Non-dt platforms may also want to register pinctrl mappings from code which is build as a module, which requires being able to unregister the mapping when the module is unloaded to avoid dangling pointers. To allow unregistering the mappings the devicetree code uses 2 internal functions: pinctrl_register_map and pinctrl_unregister_map. pinctrl_register_map allows the devicetree code to tell the core to not memdup the mappings as it retains ownership of them and pinctrl_unregister_map does the unregistering, note this only works when the mappings where not memdupped. The only code relying on the memdup/shallow-copy done by pinctrl_register_mappings is arch/arm/mach-u300/core.c this commit replaces the __initdata with const, so that the shallow-copy is no longer necessary. After that we can get rid of the internal pinctrl_unregister_map function and just use pinctrl_register_mappings directly everywhere. This commit also renames pinctrl_unregister_map to pinctrl_unregister_mappings so that its naming matches its pinctrl_register_mappings counter-part and exports it. Together these 2 changes will allow non-dt platform code to register pinctrl-mappings from modules without breaking things on module unload (as they can now unregister the mapping on unload).
Unified · Split
| @@ -201,7 +201,7 @@ static unsigned long pin_highz_conf[] = { · 200 unmodified lines | ||
| 201 | 201 | }; |
| 202 | 202 | |
| 203 | 203 | /* Pin control settings */ |
| 204 | −static struct pinctrl_map __initdata u300_pinmux_map[] = { | |
| 204 | +static const struct pinctrl_map u300_pinmux_map[] = { | |
| 205 | 205 | /* anonymous maps for chip power and EMIFs */ |
| 206 | 206 | PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "power"), |
| 207 | 207 | PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "emif0"), |
| @@ -1376,8 +1376,15 @@ void devm_pinctrl_put(struct pinctrl *p) · 1375 unmodified lines | ||
| 1376 | 1376 | } |
| 1377 | 1377 | EXPORT_SYMBOL_GPL(devm_pinctrl_put); |
| 1378 | 1378 | |
| 1379 | −int pinctrl_register_map(const struct pinctrl_map *maps, unsigned num_maps, | |
| 1380 | − bool dup) | |
| 1379 | +/** | |
| 1380 | + * pinctrl_register_mappings() - register a set of pin controller mappings | |
| 1381 | + * @maps: the pincontrol mappings table to register. Note the pinctrl-core | |
| 1382 | + * keeps a reference to the passed in maps, so they should _not_ be | |
| 1383 | + * marked with __initdata. | |
| 1384 | + * @num_maps: the number of maps in the mapping table | |
| 1385 | + */ | |
| 1386 | +int pinctrl_register_mappings(const struct pinctrl_map *maps, | |
| 1387 | + unsigned num_maps) | |
| 1381 | 1388 | { |
| 1382 | 1389 | int i, ret; |
| 1383 | 1390 | struct pinctrl_maps *maps_node; |
| @@ -1430,17 +1437,8 @@ int pinctrl_register_map(const struct pinctrl_map *maps, unsigned num_maps, · 46 unmodified lines | ||
| 1430 | 1437 | if (!maps_node) |
| 1431 | 1438 | return -ENOMEM; |
| 1432 | 1439 | |
| 1440 | + maps_node->maps = maps; | |
| 1433 | 1441 | maps_node->num_maps = num_maps; |
| 1434 | − if (dup) { | |
| 1435 | − maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps, | |
| 1436 | − GFP_KERNEL); | |
| 1437 | − if (!maps_node->maps) { | |
| 1438 | − kfree(maps_node); | |
| 1439 | − return -ENOMEM; | |
| 1440 | − } | |
| 1441 | − } else { | |
| 1442 | − maps_node->maps = maps; | |
| 1443 | − } | |
| 1444 | 1442 | |
| 1445 | 1443 | mutex_lock(&pinctrl_maps_mutex); |
| 1446 | 1444 | list_add_tail(&maps_node->node, &pinctrl_maps); |
| @@ -1448,22 +1446,14 @@ int pinctrl_register_map(const struct pinctrl_map *maps, unsigned num_maps, · 1 unmodified line | ||
| 1448 | 1446 | |
| 1449 | 1447 | return 0; |
| 1450 | 1448 | } |
| 1449 | +EXPORT_SYMBOL_GPL(pinctrl_register_mappings); | |
| 1451 | 1450 | |
| 1452 | 1451 | /** |
| 1453 | − * pinctrl_register_mappings() - register a set of pin controller mappings | |
| 1454 | − * @maps: the pincontrol mappings table to register. This should probably be | |
| 1455 | − * marked with __initdata so it can be discarded after boot. This | |
| 1456 | − * function will perform a shallow copy for the mapping entries. | |
| 1457 | − * @num_maps: the number of maps in the mapping table | |
| 1452 | + * pinctrl_unregister_mappings() - unregister a set of pin controller mappings | |
| 1453 | + * @maps: the pincontrol mappings table passed to pinctrl_register_mappings() | |
| 1454 | + * when registering the mappings. | |
| 1458 | 1455 | */ |
| 1459 | −int pinctrl_register_mappings(const struct pinctrl_map *maps, | |
| 1460 | − unsigned num_maps) | |
| 1461 | −{ | |
| 1462 | − return pinctrl_register_map(maps, num_maps, true); | |
| 1463 | −} | |
| 1464 | −EXPORT_SYMBOL_GPL(pinctrl_register_mappings); | |
| 1465 | − | |
| 1466 | −void pinctrl_unregister_map(const struct pinctrl_map *map) | |
| 1456 | +void pinctrl_unregister_mappings(const struct pinctrl_map *map) | |
| 1467 | 1457 | { |
| 1468 | 1458 | struct pinctrl_maps *maps_node; |
| 1469 | 1459 | |
| @@ -1478,6 +1468,7 @@ void pinctrl_unregister_map(const struct pinctrl_map *map) · 8 unmodified lines | ||
| 1478 | 1468 | } |
| 1479 | 1469 | mutex_unlock(&pinctrl_maps_mutex); |
| 1480 | 1470 | } |
| 1471 | +EXPORT_SYMBOL_GPL(pinctrl_unregister_mappings); | |
| 1481 | 1472 | |
| 1482 | 1473 | /** |
| 1483 | 1474 | * pinctrl_force_sleep() - turn a given controller device into sleep state |
| @@ -236,10 +236,6 @@ extern struct pinctrl_gpio_range * · 235 unmodified lines | ||
| 236 | 236 | pinctrl_find_gpio_range_from_pin_nolock(struct pinctrl_dev *pctldev, |
| 237 | 237 | unsigned int pin); |
| 238 | 238 | |
| 239 | −int pinctrl_register_map(const struct pinctrl_map *maps, unsigned num_maps, | |
| 240 | − bool dup); | |
| 241 | −void pinctrl_unregister_map(const struct pinctrl_map *map); | |
| 242 | − | |
| 243 | 239 | extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev); |
| 244 | 240 | extern int pinctrl_force_default(struct pinctrl_dev *pctldev); |
| 245 | 241 | |
| @@ -51,7 +51,7 @@ void pinctrl_dt_free_maps(struct pinctrl *p) · 50 unmodified lines | ||
| 51 | 51 | struct pinctrl_dt_map *dt_map, *n1; |
| 52 | 52 | |
| 53 | 53 | list_for_each_entry_safe(dt_map, n1, &p->dt_maps, node) { |
| 54 | − pinctrl_unregister_map(dt_map->map); | |
| 54 | + pinctrl_unregister_mappings(dt_map->map); | |
| 55 | 55 | list_del(&dt_map->node); |
| 56 | 56 | dt_free_map(dt_map->pctldev, dt_map->map, |
| 57 | 57 | dt_map->num_maps); |
| @@ -92,7 +92,7 @@ static int dt_remember_or_free_map(struct pinctrl *p, const char *statename, · 34 unmodified lines | ||
| 92 | 92 | dt_map->num_maps = num_maps; |
| 93 | 93 | list_add_tail(&dt_map->node, &p->dt_maps); |
| 94 | 94 | |
| 95 | − return pinctrl_register_map(map, num_maps, false); | |
| 95 | + return pinctrl_register_mappings(map, num_maps); | |
| 96 | 96 | |
| 97 | 97 | err_free_map: |
| 98 | 98 | dt_free_map(pctldev, map, num_maps); |
| @@ -153,6 +153,7 @@ struct pinctrl_map { · 152 unmodified lines | ||
| 153 | 153 | |
| 154 | 154 | extern int pinctrl_register_mappings(const struct pinctrl_map *map, |
| 155 | 155 | unsigned num_maps); |
| 156 | +extern void pinctrl_unregister_mappings(const struct pinctrl_map *map); | |
| 156 | 157 | extern void pinctrl_provide_dummies(void); |
| 157 | 158 | #else |
| 158 | 159 | |
| @@ -162,6 +163,10 @@ static inline int pinctrl_register_mappings(const struct pinctrl_map *map, · 3 unmodified lines | ||
| 162 | 163 | return 0; |
| 163 | 164 | } |
| 164 | 165 | |
| 166 | +static inline void pinctrl_unregister_mappings(const struct pinctrl_map *map) | |
| 167 | +{ | |
| 168 | +} | |
| 169 | + | |
| 165 | 170 | static inline void pinctrl_provide_dummies(void) |
| 166 | 171 | { |
| 167 | 172 | } |