From patchwork Wed Dec 20 02:46:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yang.guang5@zte.com.cn X-Patchwork-Id: 181426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2379270dyi; Tue, 19 Dec 2023 18:47:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsjXtRxkYG2QYpByqAFGP9swbEKzrdj2/lfupVLyMTW/KwTsnJVcnMc1rL1wDLDrePcIfv X-Received: by 2002:a05:622a:60e:b0:427:822b:cad9 with SMTP id z14-20020a05622a060e00b00427822bcad9mr1254879qta.127.1703040446994; Tue, 19 Dec 2023 18:47:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703040446; cv=none; d=google.com; s=arc-20160816; b=ShXfEF/Z//KqCvvZmuNMbJ5eS9pK3OlIRVkTjzBWH2fsekJMBI6F18+2SuxRsohyGt 1WAi7j4eQRA+rBs2gce6n7be663XnqwFMLTopdcJ0BEnFlu6WQNyAFXdAm/OxL70DF9C BMsSorOsQzq6qyTQ7PKmjxn3rM7n5RjSrLLxUnyOSsJ1lk70rfMMLhgS83hTy4uCMMMJ YaeXxvDetFLv+/QTzheyQAseU9bhzUcjEc+aHn3T2RubyWca9++jvjs1ghLur7xFw3FI QRNN9bGY3vIz7I4ctytjJFeQNNDc5IAI6SROfOeD0w97Wh1y6crtSzL3s+qmuIQLu1xq AmOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:cc:to:from:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date; bh=vo0rP3z4JJTLq0WBL+RRStOnzwrLwaNZ36iEnxxqcjE=; fh=roH3Z7noFwrPHKBvbNCdIalWcrCnD6Dhfu6UjZQYABA=; b=MOPWOfC/tbxtT6JLyNszKY8UcJP7Pv9Rst/jBDW/MErbcU55R8rkoFMGABFsn294hF DJBrplF0Vced8OImd67wvWMuY0TWppd8uwVjxATwUJXqMw8yNYqC6uQ/QOXRjOZ0KwBM iMQEqLWpwjUSqU4ppZVikVTAW7xd9Hf69Zr0N96zAj8RsoX5/ZuKuyNBZ+iVUTGqBLX9 2fFJYq6moLWgM+ftkWkT78FoyKbVseFWYAIJVjHkN8FGsvnK+gvisdQ2KwdV6LY2iGtS FEqZ7EiJexjh8W37KH5F6/5I/D/HlRgIVtZiqS5R/8Rt1wF1FG7GuZZUZslSU96YPUK4 Ww7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-6300-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6300-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b19-20020ac86bd3000000b00417a09a99b2si25186129qtt.724.2023.12.19.18.47.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 18:47:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6300-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-6300-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6300-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C3D631C25649 for ; Wed, 20 Dec 2023 02:47:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE085168B3; Wed, 20 Dec 2023 02:47:03 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) (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 31C0F14F72 for ; Wed, 20 Dec 2023 02:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mxct.zte.com.cn (unknown [192.168.251.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4Svyd457zFz8XrRJ for ; Wed, 20 Dec 2023 10:46:48 +0800 (CST) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4Svycr233Gz4xVcb; Wed, 20 Dec 2023 10:46:36 +0800 (CST) Received: from xaxapp03.zte.com.cn ([10.88.97.17]) by mse-fl2.zte.com.cn with SMTP id 3BK2kTsI065941; Wed, 20 Dec 2023 10:46:29 +0800 (+08) (envelope-from yang.guang5@zte.com.cn) Received: from mapi (xaxapp03[null]) by mapi (Zmail) with MAPI id mid31; Wed, 20 Dec 2023 10:46:30 +0800 (CST) Date: Wed, 20 Dec 2023 10:46:30 +0800 (CST) X-Zmail-TransId: 2afb6582558662c-ceb76 X-Mailer: Zmail v1.0 Message-ID: <202312201046309071520@zte.com.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: Cc: , , , , , , , , , , , , , , , , , , Subject: =?utf-8?q?=5BPATCH_linux-next=5D_drm/amd/display=3A_use_kcalloc_ins?= =?utf-8?q?tead_of_open_coded_arithmetic?= X-MAIL: mse-fl2.zte.com.cn 3BK2kTsI065941 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 65825598.000/4Svyd457zFz8XrRJ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785767339883914668 X-GMAIL-MSGID: 1785767339883914668 From: Yang Guang Dynamic size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. Signed-off-by: Chen Haonan --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index d7ac020bd8af..d6d63bd7482e 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -9204,7 +9204,7 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state) * Here we create an empty update on each plane. * To fix this, DC should permit updating only stream properties. */ - dummy_updates = kzalloc(sizeof(struct dc_surface_update) * MAX_SURFACES, GFP_ATOMIC); + dummy_updates = kcalloc(MAX_SURFACES, sizeof(struct dc_surface_update), GFP_ATOMIC); for (j = 0; j < status->plane_count; j++) dummy_updates[j].surface = status->plane_states[0];