lkml.org 
[lkml]   [2012]   [Jan]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 2/4] pinctrl: Fix pinmux_hog_maps when ctrl_dev_name is not set
* Tony Lindgren <tony@atomide.com> [120120 09:06]:
> * Stephen Warren <swarren@nvidia.com> [120120 08:24]:
> > Tony Lindgren wrote at Friday, January 20, 2012 9:17 AM:
> > > The ctrl_dev_name is optional for struct pinmux_map assuming
> > > that ctrl_dev is set. Without this patch we can get:
> > >
> > > Unable to handle kernel NULL pointer dereference at virtual address 00000000
> >
> > > diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
> >
> >
> > > @@ -992,9 +992,12 @@ int pinmux_hog_maps(struct pinctrl_dev *pctldev)
> > >
> > > for (i = 0; i < pinmux_maps_num; i++) {
> > > struct pinmux_map const *map = &pinmux_maps[i];
> > > + int match_found = 0;
> > >
> > > - if (((map->ctrl_dev == dev) ||
> > > - !strcmp(map->ctrl_dev_name, devname)) &&
> > > + if (map->ctrl_dev_name && !strcmp(map->ctrl_dev_name, devname))
> > > + match_found = 1;
> > > +
> > > + if (((map->ctrl_dev == dev) || match_found) &&
> > > map->hog_on_boot) {
> > > /* OK time to hog! */
> > > ret = pinmux_hog_map(pctldev, map);
> >
> > Wouldn't it be better if match_found was true for all matching cases,
> > in other words for the new code to be:
> >
> > int match_found = 0;
> >
> > if (map->ctrl_dev_name && !strcmp(map->ctrl_dev_name, devname))
> > match_found = 1;
> > if (map->ctrl_dev == dev)
> > match_found = 1;
> > if (match_found && map->hog_on_boot) {
>
> OK will take a look, that would make the code easier to read.

Here's this one updated, looks like we can keep it readable
even without match_found if we continue the search early based
on !map->hog_on_boot.

Regards,

Tony


From: Tony Lindgren <tony@atomide.com>
Date: Fri, 20 Jan 2012 07:43:53 -0800
Subject: [PATCH] pinctrl: Fix pinmux_hog_maps when ctrl_dev_name is not set

The ctrl_dev_name is optional for struct pinmux_map assuming
that ctrl_dev is set. Without this patch we can get:

Unable to handle kernel NULL pointer dereference at virtual address 00000000
...
(pinmux_hog_maps+0xa4/0x20c)
(pinctrl_register+0x2a4/0x378)
...

Fix this by adding adding a test for map->ctrl_dev.
Additionally move the test for map->ctrl_dev earlier
to optimize out the loop a bit.

Signed-off-by: Tony Lindgren <tony@atomide.com>

--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -993,9 +993,12 @@ int pinmux_hog_maps(struct pinctrl_dev *pctldev)
for (i = 0; i < pinmux_maps_num; i++) {
struct pinmux_map const *map = &pinmux_maps[i];

- if (((map->ctrl_dev == dev) ||
- !strcmp(map->ctrl_dev_name, devname)) &&
- map->hog_on_boot) {
+ if (!map->hog_on_boot)
+ continue;
+
+ if ((map->ctrl_dev == dev) ||
+ (map->ctrl_dev_name &&
+ !strcmp(map->ctrl_dev_name, devname))) {
/* OK time to hog! */
ret = pinmux_hog_map(pctldev, map);
if (ret)

\
 
 \ /
  Last update: 2012-01-25 01:25    [W:0.095 / U:3.336 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site