mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Harmstone <maharmstone@meta.com>
To: Mirsad Todorovac <mtodorovac69@gmail.com>,
	Alex Deucher <alexander.deucher@amd.com>,
	Victor Skvortsov <victor.skvortsov@amd.com>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "Christian König" <christian.koenig@amd.com>,
	"Xinhui Pan" <Xinhui.Pan@amd.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>, "Chris Mason" <clm@meta.com>,
	"Josef Bacik" <josef@toxicpanda.com>,
	"David Sterba" <dsterba@suse.com>,
	"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH v1 3/3] btrfs: replace kmalloc() and memcpy() with kmemdup()
Date: Wed, 18 Dec 2024 10:32:36 +0000	[thread overview]
Message-ID: <2b4d265c-0efe-43b4-890e-dbab59d9d7b0@meta.com> (raw)
In-Reply-To: <20241217225811.2437150-6-mtodorovac69@gmail.com>

There's a fix for this already in the for-next branch:
https://github.com/btrfs/linux/commit/1a287050962c6847fa4918d6b2a0f4cee35c6943

On 17/12/24 22:58, Mirsad Todorovac wrote:
> > 
> The static analyser tool gave the following advice:
> 
> ./fs/btrfs/ioctl.c:4987:9-16: WARNING opportunity for kmemdup
> 
>     4986                 if (!iov) {
>   → 4987                         iov = kmalloc(sizeof(struct iovec) * args.iovcnt, GFP_NOFS);
>     4988                         if (!iov) {
>     4989                                 unlock_extent(io_tree, start, lockend, &cached_state);
>     4990                                 btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
>     4991                                 ret = -ENOMEM;
>     4992                                 goto out_acct;
>     4993                         }
>     4994
>   → 4995                         memcpy(iov, iovstack, sizeof(struct iovec) * args.iovcnt);
>     4996                 }
> 
> Replacing kmalloc() + memcpy() with kmemdump() doesn't change semantics.
> Original code works without fault, so this is not a bug fix but proposed improvement.
> 
> Link: https://urldefense.com/v3/__https://lwn.net/Articles/198928/__;!!Bt8RZUm9aw!4OVzQmIUbyH-UGdUwMAL582hR4Q-7HN2fn9IpyxeA1T8qrcC8RdBVz4xuL4m35_kksUllAi6OmdbRehcFpwfHw$
> Fixes: 34310c442e175 ("btrfs: add io_uring command for encoded reads (ENCODED_READ ioctl)")
> Cc: Chris Mason <clm@fb.com>
> Cc: Josef Bacik <josef@toxicpanda.com>
> Cc: David Sterba <dsterba@suse.com>
> Cc: linux-btrfs@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Mirsad Todorovac <mtodorovac69@gmail.com>
> ---
>   v1:
> 	initial version.
> 
>   fs/btrfs/ioctl.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 3af8bb0c8d75..c2f769334d3c 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -4984,15 +4984,13 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
>   		 * undo this.
>   		 */
>   		if (!iov) {
> -			iov = kmalloc(sizeof(struct iovec) * args.iovcnt, GFP_NOFS);
> +			iov = kmemdup(iovstack, sizeof(struct iovec) * args.iovcnt, GFP_NOFS);
>   			if (!iov) {
>   				unlock_extent(io_tree, start, lockend, &cached_state);
>   				btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
>   				ret = -ENOMEM;
>   				goto out_acct;
>   			}
> -
> -			memcpy(iov, iovstack, sizeof(struct iovec) * args.iovcnt);
>   		}
>   
>   		count = min_t(u64, iov_iter_count(&iter), disk_io_size);


  reply	other threads:[~2024-12-18 10:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-17 22:58 [PATCH v1 1/3] drm/admgpu: " Mirsad Todorovac
2024-12-17 22:58 ` [PATCH v1 2/3] xfs/libxfs: " Mirsad Todorovac
2024-12-19  0:35   ` Darrick J. Wong
2024-12-29 12:58     ` Andrey Albershteyn
2025-01-06 19:37       ` Darrick J. Wong
2025-01-09  8:49   ` Carlos Maiolino
2025-01-14 10:28   ` Carlos Maiolino
2024-12-17 22:58 ` [PATCH v1 3/3] btrfs: " Mirsad Todorovac
2024-12-18 10:32   ` Mark Harmstone [this message]
2024-12-18 17:03     ` Mirsad Todorovac
2024-12-18  8:03 ` [PATCH v1 1/3] drm/admgpu: " Lazar, Lijo
2024-12-18 14:47   ` Alex Deucher
2025-01-14 10:30 ` Carlos Maiolino
2025-01-14 14:27   ` Alex Deucher
2025-01-14 15:33     ` Carlos Maiolino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b4d265c-0efe-43b4-890e-dbab59d9d7b0@meta.com \
    --to=maharmstone@meta.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=clm@meta.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtodorovac69@gmail.com \
    --cc=simona@ffwll.ch \
    --cc=victor.skvortsov@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®