Skip to content

Commit

Permalink
ARM: OMAP2+: Fix null pointer dereference and memory leak in omap_soc…
Browse files Browse the repository at this point in the history
…_device_init

[ Upstream commit c72b9c3 ]

kasprintf() returns a pointer to dynamically allocated memory which can
be NULL upon failure. When 'soc_dev_attr->family' is NULL,it'll trigger
the null pointer dereference issue, such as in 'soc_info_show'.

And when 'soc_device_register' fails, it's necessary to release
'soc_dev_attr->family' to avoid memory leaks.

Fixes: 6770b21 ("ARM: OMAP2+: Export SoC information to userspace")
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Message-ID: <20231123145237.609442-1-chentao@kylinos.cn>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
KunWuChan authored and gregkh committed Jan 8, 2024
1 parent 195b64e commit 3544402
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arch/arm/mach-omap2/id.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,15 @@ void __init omap_soc_device_init(void)

soc_dev_attr->machine = soc_name;
soc_dev_attr->family = omap_get_family();
if (!soc_dev_attr->family) {
kfree(soc_dev_attr);
return;
}
soc_dev_attr->revision = soc_rev;

soc_dev = soc_device_register(soc_dev_attr);
if (IS_ERR(soc_dev)) {
kfree(soc_dev_attr->family);
kfree(soc_dev_attr);
return;
}
Expand Down

0 comments on commit 3544402

Please sign in to comment.