From nobody Fri Dec 19 08:56:28 2025 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4246125DB for ; Mon, 2 Sep 2024 02:24:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725243884; cv=none; b=OZwNl8S8NCi48IiWL7E9AXVjYBJskUNL06Mw25Np6YliKP/xFVlPHFcOpBQWv6ZGatK/sOk7cBdPH3HlB1rrYfzxayfcaFrTx7u7GOruLZBxDRrJwOXFN02hdPK7ZiG73yFg+8yaEFa/7b7lTi3/tk6KzOV14g2XHanm9YLgAuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725243884; c=relaxed/simple; bh=DbnB/77JD3PvxECKqFqF1mhRi0Nld/ggLyEXaYpySec=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=AlCZTxJpsUux155W6mvqLslUpQXcwiyTA/vgIKDGjnLt222htmuJNOhY6mbvHWDieZhw+nSKja/4YT7YkVDUSLB80Qt0xZYle5t6lh4Y8evMZ0lqlTi+5hLVBqgBv4tJzUyr6FSfSbIcB3L+OzbkfwED3PANmgwuaPY8mEU6Wuk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Wxsxr4rhVz1BK36; Mon, 2 Sep 2024 10:23:44 +0800 (CST) Received: from kwepemh500013.china.huawei.com (unknown [7.202.181.146]) by mail.maildlp.com (Postfix) with ESMTPS id F0C2D1800FE; Mon, 2 Sep 2024 10:24:38 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemh500013.china.huawei.com (7.202.181.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 2 Sep 2024 10:24:38 +0800 From: Jinjie Ruan To: , , , , , , , , CC: Subject: [PATCH -next v2] drm/imagination: Use memdup_user() helper Date: Mon, 2 Sep 2024 10:33:00 +0800 Message-ID: <20240902023300.1214753-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemh500013.china.huawei.com (7.202.181.146) Content-Type: text/plain; charset="utf-8" Switching to memdup_user(), which combines kmalloc() and copy_from_user(), and it can simplfy code. Signed-off-by: Jinjie Ruan Suggested-by: Christophe JAILLET Reviewed-by: Frank Binns --- v2: - Add suggested-by. - Simplify the code. --- drivers/gpu/drm/imagination/pvr_context.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_context.c b/drivers/gpu/drm/im= agination/pvr_context.c index eded5e955cc0..98327f9bbd9c 100644 --- a/drivers/gpu/drm/imagination/pvr_context.c +++ b/drivers/gpu/drm/imagination/pvr_context.c @@ -69,24 +69,12 @@ process_static_context_state(struct pvr_device *pvr_dev= , const struct pvr_stream void *stream; int err; =20 - stream =3D kzalloc(stream_size, GFP_KERNEL); - if (!stream) - return -ENOMEM; - - if (copy_from_user(stream, u64_to_user_ptr(stream_user_ptr), stream_size)= ) { - err =3D -EFAULT; - goto err_free; - } + stream =3D memdup_user(u64_to_user_ptr(stream_user_ptr), stream_size); + if (IS_ERR(stream)) + return PTR_ERR(stream); =20 err =3D pvr_stream_process(pvr_dev, cmd_defs, stream, stream_size, dest); - if (err) - goto err_free; - - kfree(stream); - - return 0; =20 -err_free: kfree(stream); =20 return err; --=20 2.34.1