History

pinctrl: Allow modules to use pinctrl_[un]register_mappings

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).

Hans de Goede committed 6 years ago

Commit c72bed21 parent e42617b5 files · +24 −32Browse files

Showing the changes to include/linux (1 of 5 files). Show all

Unified · Split

include/linux/pinctrl/machine.h+5−0
@@ -153,6 +153,7 @@ struct pinctrl_map { · 152 unmodified lines
153 153
154extern int pinctrl_register_mappings(const struct pinctrl_map *map,154extern int pinctrl_register_mappings(const struct pinctrl_map *map,
155 unsigned num_maps);155 unsigned num_maps);
156extern void pinctrl_unregister_mappings(const struct pinctrl_map *map);
156extern void pinctrl_provide_dummies(void);157extern void pinctrl_provide_dummies(void);
157#else158#else
158 159
@@ -162,6 +163,10 @@ static inline int pinctrl_register_mappings(const struct pinctrl_map *map, · 3 unmodified lines
162 return 0;163 return 0;
163}164}
164 165
166static inline void pinctrl_unregister_mappings(const struct pinctrl_map *map)
167{
168}
169
165static inline void pinctrl_provide_dummies(void)170static inline void pinctrl_provide_dummies(void)
166{171{
167}172}