[PATCH] firmware: meson_sm: fix to avoid potential NULL pointer dereference

Zhang Shurong posted 1 patch 2 years, 6 months ago
drivers/firmware/meson/meson_sm.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] firmware: meson_sm: fix to avoid potential NULL pointer dereference
Posted by Zhang Shurong 2 years, 6 months ago
of_match_device() may fail and returns a NULL pointer.

Fix this by checking the return value of of_match_device.

Fixes: 8cde3c2153e8 ("firmware: meson_sm: Rework driver as a proper platform driver")
Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
---
 drivers/firmware/meson/meson_sm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c
index 798bcdb05d84..9a2656d73600 100644
--- a/drivers/firmware/meson/meson_sm.c
+++ b/drivers/firmware/meson/meson_sm.c
@@ -292,6 +292,8 @@ static int __init meson_sm_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	chip = of_match_device(meson_sm_ids, dev)->data;
+	if (!chip)
+		return -EINVAL;
 
 	if (chip->cmd_shmem_in_base) {
 		fw->sm_shmem_in_base = meson_sm_map_shmem(chip->cmd_shmem_in_base,
-- 
2.30.2
Re: [PATCH] firmware: meson_sm: fix to avoid potential NULL pointer dereference
Posted by Neil Armstrong 2 years, 6 months ago
Hi,

On Sat, 15 Jul 2023 22:13:38 +0800, Zhang Shurong wrote:
> of_match_device() may fail and returns a NULL pointer.
> 
> Fix this by checking the return value of of_match_device.
> 
> 

Thanks, Applied to https://git.kernel.org/pub/scm/linux/kernel/git/amlogic/linux.git (v6.6/drivers)

[1/1] firmware: meson_sm: fix to avoid potential NULL pointer dereference
      https://git.kernel.org/amlogic/c/b18226ffd0807446020841d0c56231518d4efba6

These changes has been applied on the intermediate git tree [1].

The v6.6/drivers branch will then be sent via a formal Pull Request to the Linux SoC maintainers
for inclusion in their intermediate git branches in order to be sent to Linus during
the next merge window, or sooner if it's a set of fixes.

In the cases of fixes, those will be merged in the current release candidate
kernel and as soon they appear on the Linux master branch they will be
backported to the previous Stable and Long-Stable kernels [2].

The intermediate git branches are merged daily in the linux-next tree [3],
people are encouraged testing these pre-release kernels and report issues on the
relevant mailing-lists.

If problems are discovered on those changes, please submit a signed-off-by revert
patch followed by a corrective changeset.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/amlogic/linux.git
[2] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
[3] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git

-- 
Neil
Re: [PATCH] firmware: meson_sm: fix to avoid potential NULL pointer dereference
Posted by neil.armstrong@linaro.org 2 years, 6 months ago
On 15/07/2023 16:13, Zhang Shurong wrote:
> of_match_device() may fail and returns a NULL pointer.
> 
> Fix this by checking the return value of of_match_device.
> 
> Fixes: 8cde3c2153e8 ("firmware: meson_sm: Rework driver as a proper platform driver")
> Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
> ---
>   drivers/firmware/meson/meson_sm.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c
> index 798bcdb05d84..9a2656d73600 100644
> --- a/drivers/firmware/meson/meson_sm.c
> +++ b/drivers/firmware/meson/meson_sm.c
> @@ -292,6 +292,8 @@ static int __init meson_sm_probe(struct platform_device *pdev)
>   		return -ENOMEM;
>   
>   	chip = of_match_device(meson_sm_ids, dev)->data;
> +	if (!chip)
> +		return -EINVAL;
>   
>   	if (chip->cmd_shmem_in_base) {
>   		fw->sm_shmem_in_base = meson_sm_map_shmem(chip->cmd_shmem_in_base,


Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>