2022-12-20 03:12:58

by Jiasheng Jiang

[permalink] [raw]
Subject: [PATCH] HID: amd_sfh: Add missing check for dma_alloc_coherent

Add check for the return value of the dma_alloc_coherent since
it may return NULL pointer if allocation fails.

Fixes: 4b2c53d93a4b ("SFH:Transport Driver to add support of AMD Sensor Fusion Hub (SFH)")
Signed-off-by: Jiasheng Jiang <[email protected]>
---
drivers/hid/amd-sfh-hid/amd_sfh_client.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_client.c b/drivers/hid/amd-sfh-hid/amd_sfh_client.c
index 8275bba63611..ab125f79408f 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_client.c
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_client.c
@@ -237,6 +237,10 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
in_data->sensor_virt_addr[i] = dma_alloc_coherent(dev, sizeof(int) * 8,
&cl_data->sensor_dma_addr[i],
GFP_KERNEL);
+ if (!in_data->sensor_virt_addr[i]) {
+ rc = -ENOMEM;
+ goto cleanup;
+ }
cl_data->sensor_sts[i] = SENSOR_DISABLED;
cl_data->sensor_requested_cnt[i] = 0;
cl_data->cur_hid_dev = i;
--
2.25.1


2022-12-20 07:17:22

by Basavaraj Natikar

[permalink] [raw]
Subject: Re: [PATCH] HID: amd_sfh: Add missing check for dma_alloc_coherent


On 12/20/2022 8:19 AM, Jiasheng Jiang wrote:
> Add check for the return value of the dma_alloc_coherent since
> it may return NULL pointer if allocation fails.
>
> Fixes: 4b2c53d93a4b ("SFH:Transport Driver to add support of AMD Sensor Fusion Hub (SFH)")
> Signed-off-by: Jiasheng Jiang <[email protected]>
> ---
> drivers/hid/amd-sfh-hid/amd_sfh_client.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_client.c b/drivers/hid/amd-sfh-hid/amd_sfh_client.c
> index 8275bba63611..ab125f79408f 100644
> --- a/drivers/hid/amd-sfh-hid/amd_sfh_client.c
> +++ b/drivers/hid/amd-sfh-hid/amd_sfh_client.c
> @@ -237,6 +237,10 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
> in_data->sensor_virt_addr[i] = dma_alloc_coherent(dev, sizeof(int) * 8,
> &cl_data->sensor_dma_addr[i],
> GFP_KERNEL);
> + if (!in_data->sensor_virt_addr[i]) {
> + rc = -ENOMEM;
> + goto cleanup;
> + }
> cl_data->sensor_sts[i] = SENSOR_DISABLED;
> cl_data->sensor_requested_cnt[i] = 0;
> cl_data->cur_hid_dev = i;

looks good to me.

Acked-by: Basavaraj Natikar <[email protected]>

Thanks,
--
Basavaraj

2022-12-20 11:13:37

by Benjamin Tissoires

[permalink] [raw]
Subject: Re: [PATCH] HID: amd_sfh: Add missing check for dma_alloc_coherent

On Tue, Dec 20, 2022 at 7:53 AM Basavaraj Natikar <[email protected]> wrote:
>
>
> On 12/20/2022 8:19 AM, Jiasheng Jiang wrote:
> > Add check for the return value of the dma_alloc_coherent since
> > it may return NULL pointer if allocation fails.
> >
> > Fixes: 4b2c53d93a4b ("SFH:Transport Driver to add support of AMD Sensor Fusion Hub (SFH)")
> > Signed-off-by: Jiasheng Jiang <[email protected]>
> > ---
> > drivers/hid/amd-sfh-hid/amd_sfh_client.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_client.c b/drivers/hid/amd-sfh-hid/amd_sfh_client.c
> > index 8275bba63611..ab125f79408f 100644
> > --- a/drivers/hid/amd-sfh-hid/amd_sfh_client.c
> > +++ b/drivers/hid/amd-sfh-hid/amd_sfh_client.c
> > @@ -237,6 +237,10 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
> > in_data->sensor_virt_addr[i] = dma_alloc_coherent(dev, sizeof(int) * 8,
> > &cl_data->sensor_dma_addr[i],
> > GFP_KERNEL);
> > + if (!in_data->sensor_virt_addr[i]) {
> > + rc = -ENOMEM;
> > + goto cleanup;
> > + }
> > cl_data->sensor_sts[i] = SENSOR_DISABLED;
> > cl_data->sensor_requested_cnt[i] = 0;
> > cl_data->cur_hid_dev = i;
>
> looks good to me.
>
> Acked-by: Basavaraj Natikar <[email protected]>

Thanks.

I have now applied this patch to hid.git branch for-6.2/upstream-fixes.

Cheers,
Benjamin