@@ -92,8 +92,9 @@ static void tegra_pinctrl_pin_dbg_show(struct pinctrl_dev *pctldev,
9292}
9393#endif
9494
95- static int reserve_map (struct pinctrl_map * * map , unsigned * reserved_maps ,
96- unsigned * num_maps , unsigned reserve )
95+ static int reserve_map (struct device * dev , struct pinctrl_map * * map ,
96+ unsigned * reserved_maps , unsigned * num_maps ,
97+ unsigned reserve )
9798{
9899 unsigned old_num = * reserved_maps ;
99100 unsigned new_num = * num_maps + reserve ;
@@ -103,8 +104,10 @@ static int reserve_map(struct pinctrl_map **map, unsigned *reserved_maps,
103104 return 0 ;
104105
105106 new_map = krealloc (* map , sizeof (* new_map ) * new_num , GFP_KERNEL );
106- if (!new_map )
107+ if (!new_map ) {
108+ dev_err (dev , "krealloc(map) failed\n" );
107109 return - ENOMEM ;
110+ }
108111
109112 memset (new_map + old_num , 0 , (new_num - old_num ) * sizeof (* new_map ));
110113
@@ -118,7 +121,7 @@ static int add_map_mux(struct pinctrl_map **map, unsigned *reserved_maps,
118121 unsigned * num_maps , const char * group ,
119122 const char * function )
120123{
121- if (* num_maps == * reserved_maps )
124+ if (WARN_ON ( * num_maps == * reserved_maps ) )
122125 return - ENOSPC ;
123126
124127 (* map )[* num_maps ].type = PIN_MAP_TYPE_MUX_GROUP ;
@@ -129,19 +132,22 @@ static int add_map_mux(struct pinctrl_map **map, unsigned *reserved_maps,
129132 return 0 ;
130133}
131134
132- static int add_map_configs (struct pinctrl_map * * map , unsigned * reserved_maps ,
133- unsigned * num_maps , const char * group ,
134- unsigned long * configs , unsigned num_configs )
135+ static int add_map_configs (struct device * dev , struct pinctrl_map * * map ,
136+ unsigned * reserved_maps , unsigned * num_maps ,
137+ const char * group , unsigned long * configs ,
138+ unsigned num_configs )
135139{
136140 unsigned long * dup_configs ;
137141
138- if (* num_maps == * reserved_maps )
142+ if (WARN_ON ( * num_maps == * reserved_maps ) )
139143 return - ENOSPC ;
140144
141145 dup_configs = kmemdup (configs , num_configs * sizeof (* dup_configs ),
142146 GFP_KERNEL );
143- if (!dup_configs )
147+ if (!dup_configs ) {
148+ dev_err (dev , "kmemdup(configs) failed\n" );
144149 return - ENOMEM ;
150+ }
145151
146152 (* map )[* num_maps ].type = PIN_MAP_TYPE_CONFIGS_GROUP ;
147153 (* map )[* num_maps ].data .configs .group_or_pin = group ;
@@ -152,17 +158,19 @@ static int add_map_configs(struct pinctrl_map **map, unsigned *reserved_maps,
152158 return 0 ;
153159}
154160
155- static int add_config (unsigned long * * configs , unsigned * num_configs ,
156- unsigned long config )
161+ static int add_config (struct device * dev , unsigned long * * configs ,
162+ unsigned * num_configs , unsigned long config )
157163{
158164 unsigned old_num = * num_configs ;
159165 unsigned new_num = old_num + 1 ;
160166 unsigned long * new_configs ;
161167
162168 new_configs = krealloc (* configs , sizeof (* new_configs ) * new_num ,
163169 GFP_KERNEL );
164- if (!new_configs )
170+ if (!new_configs ) {
171+ dev_err (dev , "krealloc(configs) failed\n" );
165172 return - ENOMEM ;
173+ }
166174
167175 new_configs [old_num ] = config ;
168176
@@ -203,7 +211,8 @@ static const struct cfg_param {
203211 {"nvidia,slew-rate-rising" , TEGRA_PINCONF_PARAM_SLEW_RATE_RISING },
204212};
205213
206- int tegra_pinctrl_dt_subnode_to_map (struct device_node * np ,
214+ int tegra_pinctrl_dt_subnode_to_map (struct device * dev ,
215+ struct device_node * np ,
207216 struct pinctrl_map * * map ,
208217 unsigned * reserved_maps ,
209218 unsigned * num_maps )
@@ -219,16 +228,25 @@ int tegra_pinctrl_dt_subnode_to_map(struct device_node *np,
219228 const char * group ;
220229
221230 ret = of_property_read_string (np , "nvidia,function" , & function );
222- if (ret < 0 )
231+ if (ret < 0 ) {
232+ /* EINVAL=missing, which is fine since it's optional */
233+ if (ret != - EINVAL )
234+ dev_err (dev ,
235+ "could not parse property nvidia,function\n" );
223236 function = NULL ;
237+ }
224238
225239 for (i = 0 ; i < ARRAY_SIZE (cfg_params ); i ++ ) {
226240 ret = of_property_read_u32 (np , cfg_params [i ].property , & val );
227241 if (!ret ) {
228242 config = TEGRA_PINCONF_PACK (cfg_params [i ].param , val );
229- ret = add_config (& configs , & num_configs , config );
243+ ret = add_config (dev , & configs , & num_configs , config );
230244 if (ret < 0 )
231245 goto exit ;
246+ /* EINVAL=missing, which is fine since it's optional */
247+ } else if (ret != - EINVAL ) {
248+ dev_err (dev , "could not parse property %s\n" ,
249+ cfg_params [i ].property );
232250 }
233251 }
234252
@@ -238,11 +256,13 @@ int tegra_pinctrl_dt_subnode_to_map(struct device_node *np,
238256 if (num_configs )
239257 reserve ++ ;
240258 ret = of_property_count_strings (np , "nvidia,pins" );
241- if (ret < 0 )
259+ if (ret < 0 ) {
260+ dev_err (dev , "could not parse property nvidia,pins\n" );
242261 goto exit ;
262+ }
243263 reserve *= ret ;
244264
245- ret = reserve_map (map , reserved_maps , num_maps , reserve );
265+ ret = reserve_map (dev , map , reserved_maps , num_maps , reserve );
246266 if (ret < 0 )
247267 goto exit ;
248268
@@ -255,8 +275,9 @@ int tegra_pinctrl_dt_subnode_to_map(struct device_node *np,
255275 }
256276
257277 if (num_configs ) {
258- ret = add_map_configs (map , reserved_maps , num_maps ,
259- group , configs , num_configs );
278+ ret = add_map_configs (dev , map , reserved_maps ,
279+ num_maps , group , configs ,
280+ num_configs );
260281 if (ret < 0 )
261282 goto exit ;
262283 }
@@ -282,8 +303,8 @@ int tegra_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
282303 * num_maps = 0 ;
283304
284305 for_each_child_of_node (np_config , np ) {
285- ret = tegra_pinctrl_dt_subnode_to_map (np , map , & reserved_maps ,
286- num_maps );
306+ ret = tegra_pinctrl_dt_subnode_to_map (pctldev -> dev , np , map ,
307+ & reserved_maps , num_maps );
287308 if (ret < 0 ) {
288309 tegra_pinctrl_dt_free_map (pctldev , * map , * num_maps );
289310 return ret ;
@@ -342,14 +363,14 @@ static int tegra_pinctrl_enable(struct pinctrl_dev *pctldev, unsigned function,
342363
343364 g = & pmx -> soc -> groups [group ];
344365
345- if (g -> mux_reg < 0 )
366+ if (WARN_ON ( g -> mux_reg < 0 ) )
346367 return - EINVAL ;
347368
348369 for (i = 0 ; i < ARRAY_SIZE (g -> funcs ); i ++ ) {
349370 if (g -> funcs [i ] == function )
350371 break ;
351372 }
352- if (i == ARRAY_SIZE (g -> funcs ))
373+ if (WARN_ON ( i == ARRAY_SIZE (g -> funcs ) ))
353374 return - EINVAL ;
354375
355376 val = pmx_readl (pmx , g -> mux_bank , g -> mux_reg );
@@ -369,7 +390,7 @@ static void tegra_pinctrl_disable(struct pinctrl_dev *pctldev,
369390
370391 g = & pmx -> soc -> groups [group ];
371392
372- if (g -> mux_reg < 0 )
393+ if (WARN_ON ( g -> mux_reg < 0 ) )
373394 return ;
374395
375396 val = pmx_readl (pmx , g -> mux_bank , g -> mux_reg );
@@ -490,12 +511,14 @@ static int tegra_pinconf_reg(struct tegra_pmx *pmx,
490511static int tegra_pinconf_get (struct pinctrl_dev * pctldev ,
491512 unsigned pin , unsigned long * config )
492513{
514+ dev_err (pctldev -> dev , "pin_config_get op not supported\n" );
493515 return - ENOTSUPP ;
494516}
495517
496518static int tegra_pinconf_set (struct pinctrl_dev * pctldev ,
497519 unsigned pin , unsigned long config )
498520{
521+ dev_err (pctldev -> dev , "pin_config_set op not supported\n" );
499522 return - ENOTSUPP ;
500523}
501524
@@ -550,8 +573,10 @@ static int tegra_pinconf_group_set(struct pinctrl_dev *pctldev,
550573
551574 /* LOCK can't be cleared */
552575 if (param == TEGRA_PINCONF_PARAM_LOCK ) {
553- if ((val & BIT (bit )) && !arg )
576+ if ((val & BIT (bit )) && !arg ) {
577+ dev_err (pctldev -> dev , "LOCK bit cannot be cleared\n" );
554578 return - EINVAL ;
579+ }
555580 }
556581
557582 /* Special-case Boolean values; allow any non-zero as true */
@@ -560,8 +585,12 @@ static int tegra_pinconf_group_set(struct pinctrl_dev *pctldev,
560585
561586 /* Range-check user-supplied value */
562587 mask = (1 << width ) - 1 ;
563- if (arg & ~mask )
588+ if (arg & ~mask ) {
589+ dev_err (pctldev -> dev ,
590+ "config %lx: %x too big for %d bit register\n" ,
591+ config , arg , width );
564592 return - EINVAL ;
593+ }
565594
566595 /* Update register */
567596 val &= ~(mask << bit );
0 commit comments