From patchwork Tue Dec 17 22:58:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mirsad Todorovac X-Patchwork-Id: 13912644 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA6A2E77184 for ; Tue, 17 Dec 2024 23:00:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 69A8D10E305; Tue, 17 Dec 2024 23:00:19 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SXhkv3At"; dkim-atps=neutral Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5E80D10E305; Tue, 17 Dec 2024 23:00:18 +0000 (UTC) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5d4e2aa7ea9so3326700a12.2; Tue, 17 Dec 2024 15:00:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734476417; x=1735081217; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MFHlrKsNj2nTROqoaF03zdCs62Jx2PNpLmDst7mEkDA=; b=SXhkv3AtD8VsRt93UR40e+s81l1p16glyUpc/S7Cz6DzKmzv1A+wXOyzzkkv+l7I0M ec7m/aExjCScDpJ81P6J2uAjOzQp8ADHe4hZjpUaKgWTA90bjBSRWkr0ZNog6wi1hwBl e7CnGT9wn9j610vTsOgfwftq7e95lDxaL7SEN1O7PddqBCONRHa58bhX8JvyF2cWnUfP J3y5cRFxjm3Sxq3glnQnW69ZAwZBoB9VIXHfjT+BGBWhXhcnE3VX4AMczwAuuDdIQCc+ iuwHIs06vs4MhOqEPeOxmiqPhmsYMvmbZmzFzNF7RSirdM5QPa7zLieI1he2BFEr++GX tDMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734476417; x=1735081217; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MFHlrKsNj2nTROqoaF03zdCs62Jx2PNpLmDst7mEkDA=; b=v1twpg9VXhO/bDMR3qXCaOgpfHDdx+vd/g25w6uulQEHX2kneRTCD1SeGWdKdDFMxX vyt5b2OAJLZisPTOSCkrL3FQMe/rW3T1RoqZ/kyXVd9Uf2FUSBfkERlri7UzAYuhBUav QS55sr7wHOeS+3QPonxNra6MKb/cRvYXJIB/qdLVmzvuIvN8D2nKQ/4H84oY6KqlNdil RuexRlnaeyM0c5/1+/Zwekyd5hpuzeGDBhAY3K7iX5MFiUgreLPAzCEhtvcbxLIEG8nq Zonrgd6W+HJFZbi7ihQA6lTQxnYeKSj6CRyOP2eyjacRgkEUskbybNStujmTWIEwah1z PG5A== X-Forwarded-Encrypted: i=1; AJvYcCVZxqadqMGt8uuoT/UmP8EWzkaG3bL9gMu312XNvfeRQRTEtDLecwAJr1I6nUwytxqhBrpwpbBrmqzv@lists.freedesktop.org, AJvYcCXcF2pt1EwCk3ci/9E+li+QLbm0wK/NzReDIOHT3sAuFRLv9DHpp5Pn3mIBoNRzpC9E7f0oiZpW@lists.freedesktop.org X-Gm-Message-State: AOJu0YyKr0HKvk8Kk0dZvIBOnu9pavOEuqqsDGXYJpZn3jJUsn3XTdtK YsiVYlzKnXxxJe72hJ7Npu60FwsDJSdGDTMHlOJS80nMtLe+i3sxHkZOmQ== X-Gm-Gg: ASbGncuZlPKQsXzIKOWxLFc4RKr75Sq4652TfMUAAAFEp4D+eE9oy7iM99dpA/yEd0j KdgUfSmFy+cuUCsAtTZOSsGkD6yIrU8ZCuHdLxUqpWB4nBaddTxMVCLT3OCNsZlXUDhaBBL0oZR 7jNs+HVhwI4D0TEVvGV28sgWSyRWFUXFSZJFeGwqpMHe9ikomPmzzRgqXpb8igrqZH2jMza8a3R 9xKWTpkz5+nvVfEkg/zlYQ5bmCk5lNEXVkGJ4AsIdHfWqbWOGlzlFvDMpW6zV9NeeEoxupb X-Google-Smtp-Source: AGHT+IGseKPOWt+FNZcwAVW2rCKFGixSzJ+XFmlitmEI87kClR53LP1fPFfQ91j/1mJmiGx0AiKAxg== X-Received: by 2002:a17:906:30cb:b0:aa6:7c36:3423 with SMTP id a640c23a62f3a-aabf46fc8fbmr37360166b.1.1734476416434; Tue, 17 Dec 2024 15:00:16 -0800 (PST) Received: from localhost (dh207-43-57.xnet.hr. [88.207.43.57]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aab9606b3a0sm487066666b.81.2024.12.17.15.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 15:00:15 -0800 (PST) From: Mirsad Todorovac To: Alex Deucher , Victor Skvortsov , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= , Xinhui Pan , David Airlie , Simona Vetter , Mirsad Todorovac , Zhigang Luo , Hawking Zhang , Lijo Lazar , Yunxiang Li , Jack Xiao , Vignesh Chander , Danijel Slivka Subject: [PATCH v1 1/3] drm/admgpu: replace kmalloc() and memcpy() with kmemdup() Date: Tue, 17 Dec 2024 23:58:10 +0100 Message-ID: <20241217225811.2437150-2-mtodorovac69@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The static analyser tool gave the following advice: ./drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:1266:7-14: WARNING opportunity for kmemdup → 1266 tmp = kmalloc(used_size, GFP_KERNEL); 1267 if (!tmp) 1268 return -ENOMEM; 1269 → 1270 memcpy(tmp, &host_telemetry->body.error_count, used_size); 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://lwn.net/Articles/198928/ Fixes: 84a2947ecc85c ("drm/amdgpu: Implement virt req_ras_err_count") Cc: Alex Deucher Cc: "Christian König" Cc: Xinhui Pan Cc: David Airlie Cc: Simona Vetter Cc: Zhigang Luo Cc: Victor Skvortsov Cc: Hawking Zhang Cc: Lijo Lazar Cc: Yunxiang Li Cc: Jack Xiao Cc: Vignesh Chander Cc: Danijel Slivka Cc: amd-gfx@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Mirsad Todorovac Reviewed-by: Lijo Lazar --- v1: initial version. drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c index c704e9803e11..0af469ec6fcc 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c @@ -1263,12 +1263,10 @@ static int amdgpu_virt_cache_host_error_counts(struct amdgpu_device *adev, if (used_size > (AMD_SRIOV_RAS_TELEMETRY_SIZE_KB << 10)) return 0; - tmp = kmalloc(used_size, GFP_KERNEL); + tmp = kmemdup(&host_telemetry->body.error_count, used_size, GFP_KERNEL); if (!tmp) return -ENOMEM; - memcpy(tmp, &host_telemetry->body.error_count, used_size); - if (checksum != amd_sriov_msg_checksum(tmp, used_size, 0, 0)) goto out; From patchwork Tue Dec 17 22:58:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mirsad Todorovac X-Patchwork-Id: 13912645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40E16E77184 for ; Tue, 17 Dec 2024 23:00:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BCB5210E27C; Tue, 17 Dec 2024 23:00:44 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Bk+A/hDr"; dkim-atps=neutral Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by gabe.freedesktop.org (Postfix) with ESMTPS id AACD410E27C; Tue, 17 Dec 2024 23:00:43 +0000 (UTC) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-aa69077b93fso873125566b.0; Tue, 17 Dec 2024 15:00:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734476442; x=1735081242; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4XEz6rhnsFVB96wbkpW+lhU7b364boMylDpIEeHqrE4=; b=Bk+A/hDr2BTE6XRhtutSMEv+cqgYWqeK+q7j2ZYJ1GBjWC5O6uYKLze8DfmLpoiW1K hKQB4W3B9WYU71jKdFVisdmNUQTpedLYklO+8yQMjoGt8bxka2UunaiZR0DrU3+Ofwre 3CFNXIbW68tOAU8c00BPNDuGDRAuD/MSORqSs8L75E06iGJ81aLLbNzNAz7yNZVgEjQT uUE/haRVg70NeEYvLbCpn0aZxsORxIk07yrPsaBoEEgkeyGkMOGYeNZ3fqm98CNl9lOM rCYwm5y3LTL7SRwZWbJI1uQns9uCWr4Krxmnn+sNSmV12yMX9SEyL0dycGpDadArAPlS cPuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734476442; x=1735081242; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4XEz6rhnsFVB96wbkpW+lhU7b364boMylDpIEeHqrE4=; b=IgbY4D89AIVcRAKbCNK2EnBQBEw0p4lSPTPmrk5X/ZnaFUQmnbt7iP0SBztYhAnwHP GXAdGUFIpzHeGfJantMTApyaEBD/TTgecVXex0OpokFFTuq/jjiEgloRz3suLz56/jiJ GlJmHwrPmw5n3p/kr3BnF8El9xqIZ9w9fXvEVV3q0/inKvpg82ZR93cT4Y06rBcMbNZQ lURe49PM/nS8MpwJ0XmRrxsz0EAWjQe/+GsVi6Y1RBQNPUuX56tIzAZ7oK7yg0lkfn1e otTNu9sqJCZ87Mwo0HdIBg8uYbjWevpyn7IRtWUZnjY4QO3vCED8cnPn0QYIRUuycCe7 u0kA== X-Forwarded-Encrypted: i=1; AJvYcCU4HdYyb7ov17siqopXuBTHQmNH9vGXU8nDTEZSU5jPppY9WfoUPN0R6zX4FusynJ5jUYe1CXjA@lists.freedesktop.org, AJvYcCXZKPmzFq425NHs4z/qVJE710YaLk0IwmjBcY7LCesCjvvMlPXfTFdRfbX4yfCDms0GtpJ1y74Hq7Z0@lists.freedesktop.org X-Gm-Message-State: AOJu0YzoSnhWJI3P5cUcWF0JKLigDqzMLAA6tTPpKulNGRsYSIgzRzOZ E+uHxLEJuIjs4zkanQQ/uDW4C3z8uqpUwrGvxgN3dMk52ng+Bh5J X-Gm-Gg: ASbGncuDL6grs4GsmkJwqT5WnfMiIw5OqW4MEI06Y2UMwTOfTkkLe2IeQeu+e5/VD3g FpMCtJc0VNTNACgBJ0wrpdWhh9m6hlSPcOE2muKOeObU1hJji9d19fvAmx3sCV5U+dJl/E2mjWH kTZdRbzDBiQaanJEkNHjSZl5M9nf7sPhQPb6xMTv7tnnLZ5be2ks7NuWlL6Qp05dVQk4DF5AEuw c6MlyNPGwC21zY5xuOMchcVOGfT15zmcDchX2QnPZby3WZrDWwRIsLY6tdbFTZqSG19ew9m X-Google-Smtp-Source: AGHT+IFQX77wgpGspEiR873ojumfcvZFoep/771Bg+U3/cA+lXsvCwJn7F5mSufydfw/ldrxkhTLGg== X-Received: by 2002:a17:907:da8:b0:aa6:a228:afa9 with SMTP id a640c23a62f3a-aabf46fbf1emr45475166b.3.1734476441886; Tue, 17 Dec 2024 15:00:41 -0800 (PST) Received: from localhost (dh207-43-57.xnet.hr. [88.207.43.57]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aab9c3eb5e0sm468944766b.44.2024.12.17.15.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 15:00:41 -0800 (PST) From: Mirsad Todorovac To: Alex Deucher , Victor Skvortsov , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= , Xinhui Pan , David Airlie , Simona Vetter , Mirsad Todorovac , Carlos Maiolino , "Darrick J. Wong" , Chandan Babu R , Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH v1 2/3] xfs/libxfs: replace kmalloc() and memcpy() with kmemdup() Date: Tue, 17 Dec 2024 23:58:12 +0100 Message-ID: <20241217225811.2437150-4-mtodorovac69@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241217225811.2437150-2-mtodorovac69@gmail.com> References: <20241217225811.2437150-2-mtodorovac69@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The source static analysis tool gave the following advice: ./fs/xfs/libxfs/xfs_dir2.c:382:15-22: WARNING opportunity for kmemdup → 382 args->value = kmalloc(len, 383 GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL); 384 if (!args->value) 385 return -ENOMEM; 386 → 387 memcpy(args->value, name, len); 388 args->valuelen = len; 389 return -EEXIST; 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://lwn.net/Articles/198928/ Fixes: 94a69db2367ef ("xfs: use __GFP_NOLOCKDEP instead of GFP_NOFS") Fixes: 384f3ced07efd ("[XFS] Return case-insensitive match for dentry cache") Fixes: 2451337dd0439 ("xfs: global error sign conversion") Cc: Carlos Maiolino Cc: "Darrick J. Wong" Cc: Chandan Babu R Cc: Dave Chinner Cc: linux-xfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Mirsad Todorovac --- v1: initial version. fs/xfs/libxfs/xfs_dir2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index 202468223bf9..24251e42bdeb 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -379,12 +379,11 @@ xfs_dir_cilookup_result( !(args->op_flags & XFS_DA_OP_CILOOKUP)) return -EEXIST; - args->value = kmalloc(len, + args->value = kmemdup(name, len, GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL); if (!args->value) return -ENOMEM; - memcpy(args->value, name, len); args->valuelen = len; return -EEXIST; } From patchwork Tue Dec 17 22:58:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mirsad Todorovac X-Patchwork-Id: 13912646 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 05FB8E77184 for ; Tue, 17 Dec 2024 23:01:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 845EA10E2E9; Tue, 17 Dec 2024 23:01:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AZ6MiMAB"; dkim-atps=neutral Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 296D210E304; Tue, 17 Dec 2024 23:01:07 +0000 (UTC) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-aab6fa3e20eso843877366b.2; Tue, 17 Dec 2024 15:01:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734476465; x=1735081265; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K2Q+5lZ93c/1180fBGK9dFi80vfh3bKphGjr5C1ObCA=; b=AZ6MiMAB751qfA0J7wk+VKzJOJzXdgL0Z4Tq75tbcLLuNxZs3ZvIpSb3KVux7sZoMo 82O8RpEI7yjHMilv1igCK0NaQnkutWDYxALcGjES8MtzxGxSVbw5obNHDm5SnFuAm3YV NqLkh0NBhxRoOB+IIqlmExzOz2kXw4upeXvGTPlDoTL8Z63VyZ9/XZ0CJ9CRA/daHnEY rj92OEGuZ4NtoRKgz+fGB1San6/uYnlFcmucDmUl8vVFF0Hm+/cy9esqxus8YvjGMlgi 3vSXy8kPHYjZOtUKm4qlzsdjuarbIRk3leziZaL/ozBMtGD3ZJJmPwmxqC7qCt4c4MHe 6e3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734476465; x=1735081265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K2Q+5lZ93c/1180fBGK9dFi80vfh3bKphGjr5C1ObCA=; b=LOwj0/DUcI0MnSIE91P09dehHnjAuQoFtQIYNFIoYHgEHmSHoS+z2/oIOhWPfTWJJJ dWfx7gXlsHwLX5U93w9Nok3a2yx913LzucxJnCgPxzwNT1v/nlpdoc58Oa5LNgQLFGZ+ W/eD20cMSfsjJutGvnJANchwRhBdlIqZgMfcq6lTqjkGF0TeJGDxadiXGMUirFqwaGjg zAF3jVreKOC0kyBJyPKCJTqd90PyXW6CqK4PTQuqz4kEe9Epf8zqNTY+6NWXsHmfpZUW UFe7Ak/PlN607h+ge/Ggu2/5UN6MNlJk7+Cj1biIDv8Psa/bi4s7ZZOQu6UH6COyjRqa ylaA== X-Forwarded-Encrypted: i=1; AJvYcCUjekN9CR7yysym3E829Co4vT9FieOgbROZPBJylpZFEQJ1Qdmwm3DPfznwHgPLwhxGZrm43G21@lists.freedesktop.org, AJvYcCXFA4o/UjAvxezhhY4ykDpxs81slh6m/Ol97XQuqIf5nGxUk5dh/FbZ8Zv75vY7r33A9RXQGLt8to2O@lists.freedesktop.org X-Gm-Message-State: AOJu0YwV02y6i+gteHr6G3AS0PAI6mfXw3tUaZdFKZRtchYFvpCYpR4J O7+9K/pFIiIdrWJFFW6YzVfMjvKDeyaFYI0M4gvSsNzJZgfDVjsZ X-Gm-Gg: ASbGncuxNMTG4RI2929+fqw0qQPAfpCnETY25qy+Z+/hplRaJ3qu3u8r5Kt/J0vXEcH O5/GQgJO4YXcQ4wYaAbIzw2tSEveP7nr+nXjiagRc0nmGJw6IQQMC6Ldp/3GK8SY3xbLYkkJUYx /fDZsfW0MEcyHoXDkfaIqcM6142f10yfTjFFVL+PrbBFG8RqzjzepXW6vbqevMAFYoAEIp+s9Oc BdrDN6b725Tsq0O4DOQk3vrusYmotdzUkJPtTkZWwsi30UBDZu38AEl5PrX1cE3RmY2OegH X-Google-Smtp-Source: AGHT+IGDgT1XC/54LMv/yuGZqK7CHwcriAKun+hCdwFovWUgDOgR+DiY5cNn7w+69HSV/VlAf9rmcw== X-Received: by 2002:a17:907:2d12:b0:aa6:8d51:8fe2 with SMTP id a640c23a62f3a-aabf48f9900mr33660766b.42.1734476465330; Tue, 17 Dec 2024 15:01:05 -0800 (PST) Received: from localhost (dh207-43-57.xnet.hr. [88.207.43.57]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aab960065f2sm494726366b.29.2024.12.17.15.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 15:01:04 -0800 (PST) From: Mirsad Todorovac To: Alex Deucher , Victor Skvortsov , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= , Xinhui Pan , David Airlie , Simona Vetter , Mirsad Todorovac , Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: [PATCH v1 3/3] btrfs: replace kmalloc() and memcpy() with kmemdup() Date: Tue, 17 Dec 2024 23:58:14 +0100 Message-ID: <20241217225811.2437150-6-mtodorovac69@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241217225811.2437150-2-mtodorovac69@gmail.com> References: <20241217225811.2437150-2-mtodorovac69@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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://lwn.net/Articles/198928/ Fixes: 34310c442e175 ("btrfs: add io_uring command for encoded reads (ENCODED_READ ioctl)") Cc: Chris Mason Cc: Josef Bacik Cc: David Sterba Cc: linux-btrfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Mirsad Todorovac --- 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);