[PATCH v2 2/4] dma-mapping: benchmark: avoid needless copy_to_user if benchmark fails

Fedor Pchelkin posted 4 patches 1 year, 7 months ago
[PATCH v2 2/4] dma-mapping: benchmark: avoid needless copy_to_user if benchmark fails
Posted by Fedor Pchelkin 1 year, 7 months ago
If do_map_benchmark() has failed, there is nothing useful to copy back
to userspace.

Suggested-by: Barry Song <21cnbao@gmail.com>
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
---
 kernel/dma/map_benchmark.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/dma/map_benchmark.c b/kernel/dma/map_benchmark.c
index 2478957cf9f8..a6edb1ef98c8 100644
--- a/kernel/dma/map_benchmark.c
+++ b/kernel/dma/map_benchmark.c
@@ -256,6 +256,9 @@ static long map_benchmark_ioctl(struct file *file, unsigned int cmd,
 		 * dma_mask changed by benchmark
 		 */
 		dma_set_mask(map->dev, old_dma_mask);
+
+		if (ret)
+			return ret;
 		break;
 	default:
 		return -EINVAL;
-- 
2.45.0
Re: [PATCH v2 2/4] dma-mapping: benchmark: avoid needless copy_to_user if benchmark fails
Posted by Robin Murphy 1 year, 7 months ago
On 2024-05-04 12:47 pm, Fedor Pchelkin wrote:
> If do_map_benchmark() has failed, there is nothing useful to copy back
> to userspace.

I guess there could be some valid partial data if for instance it failed 
due to OOM in the middle of running, but the standard tool is still 
going to ignore that if the ioctl() returns an error, so meh.

Acked-by: Robin Murphy <robin.murphy@arm.com>

> Suggested-by: Barry Song <21cnbao@gmail.com>
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> ---
>   kernel/dma/map_benchmark.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/dma/map_benchmark.c b/kernel/dma/map_benchmark.c
> index 2478957cf9f8..a6edb1ef98c8 100644
> --- a/kernel/dma/map_benchmark.c
> +++ b/kernel/dma/map_benchmark.c
> @@ -256,6 +256,9 @@ static long map_benchmark_ioctl(struct file *file, unsigned int cmd,
>   		 * dma_mask changed by benchmark
>   		 */
>   		dma_set_mask(map->dev, old_dma_mask);
> +
> +		if (ret)
> +			return ret;
>   		break;
>   	default:
>   		return -EINVAL;