Skip to content

Commit 6e64b6c

Browse files
pankajkdubeybroonie
authored andcommitted
regmap: fix NULL pointer dereference in regmap_get_val_endian
Recents commits for getting reg endianness causing NULL pointer dereference if dev is passed NULL in regmap_init_mmio. This patch fixes this issue, and allows to parse reg endianness only if dev and dev->of_node exist. Signed-off-by: Pankaj Dubey <pankaj.dubey@samsung.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent cf673fb commit 6e64b6c

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

‎drivers/base/regmap/regmap.c‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ static enum regmap_endian regmap_get_val_endian(struct device *dev,
477477
const struct regmap_bus *bus,
478478
const struct regmap_config *config)
479479
{
480-
struct device_node *np = dev->of_node;
480+
struct device_node *np;
481481
enum regmap_endian endian;
482482

483483
/* Retrieve the endianness specification from the regmap config */
@@ -487,15 +487,20 @@ static enum regmap_endian regmap_get_val_endian(struct device *dev,
487487
if (endian != REGMAP_ENDIAN_DEFAULT)
488488
return endian;
489489

490-
/* Parse the device's DT node for an endianness specification */
491-
if (of_property_read_bool(np, "big-endian"))
492-
endian = REGMAP_ENDIAN_BIG;
493-
else if (of_property_read_bool(np, "little-endian"))
494-
endian = REGMAP_ENDIAN_LITTLE;
490+
/* If the dev and dev->of_node exist try to get endianness from DT */
491+
if (dev && dev->of_node) {
492+
np = dev->of_node;
495493

496-
/* If the endianness was specified in DT, use that */
497-
if (endian != REGMAP_ENDIAN_DEFAULT)
498-
return endian;
494+
/* Parse the device's DT node for an endianness specification */
495+
if (of_property_read_bool(np, "big-endian"))
496+
endian = REGMAP_ENDIAN_BIG;
497+
else if (of_property_read_bool(np, "little-endian"))
498+
endian = REGMAP_ENDIAN_LITTLE;
499+
500+
/* If the endianness was specified in DT, use that */
501+
if (endian != REGMAP_ENDIAN_DEFAULT)
502+
return endian;
503+
}
499504

500505
/* Retrieve the endianness specification from the bus config */
501506
if (bus && bus->val_format_endian_default)

0 commit comments

Comments
 (0)