Re: [PATCH] pinctrl: make a deep copy of pinmux map

From: Arnd Bergmann
Date: Tue Nov 29 2011 - 09:24:48 EST


On Tuesday 29 November 2011, Linus Walleij wrote:
> From: Linus Walleij <linus.walleij@xxxxxxxxxx>
>
> This makes a deep copy of the pinmux function map instead of
> keeping the copy supplied from the platform around. This makes
> it possible to tag the platforms map with __initdata as is also
> done as part of this patch.
>
> Rationale: a certain target platform (PXA) has numerous
> pinmux maps, many of which will be lying around unused after
> boot in a multi-platform binary. Instead, deep-copy the one
> we're going to use and tag them all __initdata so they go away
> after boot.
>
> Suggested-by: Arnd Bergmann <arnd.bergmann@xxxxxxxxxx>
> Signed-off-by: Linus Walleij <linus.walleij@xxxxxxxxxx>

Very nice!

> /**
> * pinmux_register_mappings() - register a set of pinmux mappings
> - * @maps: the pinmux mappings table to register
> + * @maps: the pinmux mappings table to register, this should be marked with
> + * __initdata so it can be discarded after boot, this function will
> + * perform a deep copy (including strings) for the mapping entries.
> * @num_maps: the number of maps in the mapping table
> *

Is it actually necessary to copy the strings? I always thought they
end up in the constant data section even if the data structure that
they are defined in is in initdata.

> +
> + /* Allocate a deep copy of the map array */
> + pinmux_maps = kzalloc(sizeof(struct pinmux_map) * num_maps,
> + GFP_KERNEL);

I guess it's easier to use kmemdup here. At least there is no
point in zeroing the array when the next step is to overwrite it.

Arnd

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/