* [PATCH] Drivers: hv: vmbus: Add missing check for dma_set_mask in vmbus_device_register()
@ 2024-07-01 2:30 Haoxiang Li
2024-07-01 3:47 ` Michael Kelley
2024-07-01 9:30 ` Markus Elfring
0 siblings, 2 replies; 3+ messages in thread
From: Haoxiang Li @ 2024-07-01 2:30 UTC (permalink / raw)
To: kys, haiyangz, wei.liu, decui, parri.andrea, mikelley
Cc: linux-hyperv, linux-kernel, Haoxiang Li
child_device_obj->device cannot perform DMA properly if dma_set_mask()
returns non-zero. Add check for dma_set_mask() and return the error if it
fails. child_device_obj->device is not initialized here, so use kfree() to
free child_device_obj->device.
Fixes: 3a5469582c24 ("Drivers: hv: vmbus: Fix initialization of device object in vmbus_device_register()")
Signed-off-by: Haoxiang Li <make24@iscas.ac.cn>
---
drivers/hv/vmbus_drv.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 12a707ab73f8..daa584eaa2af 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1897,7 +1897,13 @@ int vmbus_device_register(struct hv_device *child_device_obj)
child_device_obj->device.dma_parms = &child_device_obj->dma_parms;
child_device_obj->device.dma_mask = &child_device_obj->dma_mask;
- dma_set_mask(&child_device_obj->device, DMA_BIT_MASK(64));
+ ret = dma_set_mask(&child_device_obj->device, DMA_BIT_MASK(64));
+
+ if (ret) {
+ pr_err("64-bit DMA enable failed\n");
+ kfree(&child_device_obj->device);
+ return ret;
+ }
/*
* Register with the LDM. This will kick off the driver/device
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] Drivers: hv: vmbus: Add missing check for dma_set_mask in vmbus_device_register()
2024-07-01 2:30 [PATCH] Drivers: hv: vmbus: Add missing check for dma_set_mask in vmbus_device_register() Haoxiang Li
@ 2024-07-01 3:47 ` Michael Kelley
2024-07-01 9:30 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Michael Kelley @ 2024-07-01 3:47 UTC (permalink / raw)
To: Haoxiang Li, kys, haiyangz, wei.liu, decui, parri.andrea, mikelley
Cc: linux-hyperv, linux-kernel
From: Haoxiang Li <make24@iscas.ac.cn> Sent: Sunday, June 30, 2024 7:31 PM
>
> child_device_obj->device cannot perform DMA properly if dma_set_mask()
> returns non-zero. Add check for dma_set_mask() and return the error if it
> fails. child_device_obj->device is not initialized here, so use kfree() to
> free child_device_obj->device.
>
> Fixes: 3a5469582c24 ("Drivers: hv: vmbus: Fix initialization of device object in
> vmbus_device_register()")
> Signed-off-by: Haoxiang Li <make24@iscas.ac.cn>
> ---
> drivers/hv/vmbus_drv.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> index 12a707ab73f8..daa584eaa2af 100644
> --- a/drivers/hv/vmbus_drv.c
> +++ b/drivers/hv/vmbus_drv.c
> @@ -1897,7 +1897,13 @@ int vmbus_device_register(struct hv_device
> *child_device_obj)
>
> child_device_obj->device.dma_parms = &child_device_obj->dma_parms;
> child_device_obj->device.dma_mask = &child_device_obj->dma_mask;
> - dma_set_mask(&child_device_obj->device, DMA_BIT_MASK(64));
> + ret = dma_set_mask(&child_device_obj->device, DMA_BIT_MASK(64));
> +
> + if (ret) {
> + pr_err("64-bit DMA enable failed\n");
> + kfree(&child_device_obj->device);
> + return ret;
> + }
I commented on a previous attempt to check the return value from
dma_set_mask(). See [1]. See also commit f92a4b50f0bd that adds
some detail about the error handling in vmbus_device_register(). It's
all rather messy. I have not personally worked through the details, so
I'm not sure of what the right cleanup is. But I don't think it is
sufficient to just do the kfree() as your patch proposes. Or if I'm wrong,
and that *is* sufficient, please provides details on the reasoning
why, and let's make sure to record that for future reference! :-)
Michael
[1] https://lore.kernel.org/linux-hyperv/20230607014310.19850-1-jiasheng@iscas.ac.cn/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Drivers: hv: vmbus: Add missing check for dma_set_mask in vmbus_device_register()
2024-07-01 2:30 [PATCH] Drivers: hv: vmbus: Add missing check for dma_set_mask in vmbus_device_register() Haoxiang Li
2024-07-01 3:47 ` Michael Kelley
@ 2024-07-01 9:30 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-07-01 9:30 UTC (permalink / raw)
To: Haoxiang Li, linux-hyperv, kernel-janitors, Andrea Parri,
Dexuan Cui, Haiyang Zhang, K. Y. Srinivasan, Michael Kelley,
Wei Liu
Cc: LKML
> child_device_obj->device cannot perform DMA properly if dma_set_mask()
> returns non-zero. …
Another wording suggestion:
Direct memory access can not be properly performed any more
after a dma_set_mask() call failed.
See also:
https://elixir.bootlin.com/linux/v6.10-rc6/source/kernel/dma/mapping.c#L804
> … child_device_obj->device is not initialized here, so use kfree() to
> free child_device_obj->device.
How did you come to the conclusion that meaningful data processing
would still be possible according to such information?
…
> Signed-off-by: Haoxiang Li <make24@iscas.ac.cn>
I find it interesting that another personal name is presented here.
I noticed that some patches were published with the name “Ma Ke” previously.
How will requirements be resolved for the Developer's Certificate of Origin?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.10-rc6#n398
Would you like to append parentheses to another function name in the summary phrase?
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-01 9:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-01 2:30 [PATCH] Drivers: hv: vmbus: Add missing check for dma_set_mask in vmbus_device_register() Haoxiang Li
2024-07-01 3:47 ` Michael Kelley
2024-07-01 9:30 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®