mirror of
https://github.com/torvalds/linux.git
synced 2024-12-27 13:22:23 +00:00
regmap: Allow missing device in regmap_name_read_file()
This fixes a possible NULL pointer dereference oops in regmap_name_read_file() when the regmap does not have a device associated with it. For example syscon regmaps retrieved with syscon_regmap_lookup_by_compatible() don't have a device. Signed-off-by: David Lechner <david@lechnology.com> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
7928b2cbe5
commit
12ae3808c1
@ -40,6 +40,7 @@ static ssize_t regmap_name_read_file(struct file *file,
|
|||||||
loff_t *ppos)
|
loff_t *ppos)
|
||||||
{
|
{
|
||||||
struct regmap *map = file->private_data;
|
struct regmap *map = file->private_data;
|
||||||
|
const char *name = "nodev";
|
||||||
int ret;
|
int ret;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
@ -47,7 +48,10 @@ static ssize_t regmap_name_read_file(struct file *file,
|
|||||||
if (!buf)
|
if (!buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ret = snprintf(buf, PAGE_SIZE, "%s\n", map->dev->driver->name);
|
if (map->dev && map->dev->driver)
|
||||||
|
name = map->dev->driver->name;
|
||||||
|
|
||||||
|
ret = snprintf(buf, PAGE_SIZE, "%s\n", name);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
kfree(buf);
|
kfree(buf);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user