Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1540079rdb; Sat, 10 Feb 2024 06:21:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9hHpv/sBi+tmN0/ioIz4n3DgZ9XWtM3p1BYh1BZ5tioWl7iWmRZoegIMoy2QKrpSrFG4C X-Received: by 2002:a05:6358:7520:b0:176:5a5e:4b7c with SMTP id k32-20020a056358752000b001765a5e4b7cmr2460946rwg.6.1707574867463; Sat, 10 Feb 2024 06:21:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707574867; cv=pass; d=google.com; s=arc-20160816; b=tILCh22u33qFbk74PWc5IQBPEGZGZsCmf43KgFkPTM2zKw0z+p0k1ZkE4Emcy2uw51 FZk9L0Zd6HYYG5N66uvzz3U2ZfdXFjuUdq5eQ3aF+p4W0i+lwTc80kXxVG3Bxrw6Tz5V 2B/GoVksN/KaEDVxlVtrhwCPi3ERzs1PA/sBnUkufgdK19Qn8MoPuXluWExZmadiRmLO Pedv74j8FLMCimJdvreHCD4ilOJ0CFb6tDgjc4d5OvLJlCfPjR14jgIoSYBcx7crI3GU 0Sckdm82Dhe5LQg0RP+4D3SHn5h188Yu3L94fFwf7uMZXUEIuqoOeeCxEISE/ZV9R8Y2 CbaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature; bh=yq/cjM1AM6BfMWgTIepyUYIStt05/LYL9XG67DZ2cwk=; fh=D8Dd/aFA3QxrYYUtSm4M+aVvYyI/wi98WmHWTh4RWAg=; b=MnpwYRp8phdCCs006eU+zfpNbXy2Jpg9rO6mZyVa24mTB48YQ5UpkoKSYmRrP12PD2 CzVw/ojlvlgfhR4Tm8TU8nKAafiAr6iLSqnJihjjqTy3y/Sk8cADq96PdxrF3QgWDcwE qVwnSGk+466BC94CsJa+tjVvW4h1yeT98vtUyV1cOH85XnETAmKA3enVIKWIL6NUzx7d YQ1ZZPVmPl/EMc9gcQQY8TIN6eWkhntmsRbWwKq13oytI2ecsrUfJJP2iIn5Rbw0VV9+ 05SsEmXZULUnBYYPE+NLRZ7nO7y8bpj+ISWsCj9yqe/CR5Q4KvNnHaHJ0zZXIxYMJmFJ kVFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=CLYuoMyR; arc=pass (i=1 spf=pass spfdomain=gmx.com dkim=pass dkdomain=gmx.com dmarc=pass fromdomain=gmx.com); spf=pass (google.com: domain of linux-kernel+bounces-60422-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60422-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.com X-Forwarded-Encrypted: i=2; AJvYcCU2OVhs65hc9f8kjqZmZnP4QRXdVK01zwhtbilnXUp1Jymblw8WOIiR8+jtIU5JcU0HczO/8HmwEn6JWATE1yyY9HIWHqkIZ6G3mZE1uQ== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id kq16-20020a056a004b1000b006e090184596si2169016pfb.331.2024.02.10.06.21.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Feb 2024 06:21:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60422-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=CLYuoMyR; arc=pass (i=1 spf=pass spfdomain=gmx.com dkim=pass dkdomain=gmx.com dmarc=pass fromdomain=gmx.com); spf=pass (google.com: domain of linux-kernel+bounces-60422-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60422-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 9D964B22685 for ; Sat, 10 Feb 2024 14:20:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F3B7B53E34; Sat, 10 Feb 2024 14:20:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.com header.i=erick.archer@gmx.com header.b="CLYuoMyR" Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (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 918C836B02; Sat, 10 Feb 2024 14:19:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.22 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707574801; cv=none; b=qQDPje2GcMSi3HBQREyJBKgqRXWBMnGiZ6J7Ly2jMO7CqlLIca+wG4GoLZ+jfwYEhlKbPCnclqskIAzVeNPNnqAk7p/JYspR3KkOXtFkeeUSwXMdgCKkAmf++JTCO8SIsO+zxaLtKZTQ4qvGq4aV1V852jOvd5TnBUxxQNP1NBA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707574801; c=relaxed/simple; bh=QHEpmhKgjFPc76682sn4sIoMEGMcJgRjxAWR8n1DTeo=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=NvbYNebix/t0hDc80Ig/siiGOsfTbI5G8b4KT49twMFPCoQNnyS3INKWRaHC/ybPUGbCfmpK3rfzCId1GeMy7XoawjFzj75lHwUHMSMYuuHVS1TAKl2d4c+95ERDOIq+XWfWyxx3horuwwbbAXcW4sfxMvFjet6xRcFUDC80gH8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.com; spf=pass smtp.mailfrom=gmx.com; dkim=pass (2048-bit key) header.d=gmx.com header.i=erick.archer@gmx.com header.b=CLYuoMyR; arc=none smtp.client-ip=212.227.17.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.com; s=s31663417; t=1707574768; x=1708179568; i=erick.archer@gmx.com; bh=QHEpmhKgjFPc76682sn4sIoMEGMcJgRjxAWR8n1DTeo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=CLYuoMyR/RfpN1p89s4CKg+E1TB8++6l2iGF2gXvnfMLbE9b6PMz9cd5qyfXvSoM LPQHJpXWyckAizctYuZhkFyakdBMG/I7a9DmSRe0tF/0b7WNguKne88f7j/KCte3F K4MRd7LRL4DvnLGDvkTCU7TGBV1Q+yNcdO+R6BUancgCipkanPVP2A19nB/NiIflm bUXRyvr+amviLy1ui9nOtpmE/RS6NFzEkO7B5md3jJtsyhIHpgNcDbkixk+pmSOup gEzlkhqSoHn17evvCwaEg2zGlwXzpf8C4HelCdGUnEB6oZGlTB7H+fCyp4ONfFxw9 sxlZMwMM86q9H6GQMg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([79.157.194.183]) by mail.gmx.net (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MtfJX-1qiDsO3GNL-00vA8E; Sat, 10 Feb 2024 15:19:27 +0100 From: Erick Archer To: Lucas De Marchi , Oded Gabbay , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , "Gustavo A. R. Silva" , Kees Cook Cc: Erick Archer , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] drm/xe: Prefer struct_size over open coded arithmetic Date: Sat, 10 Feb 2024 15:19:12 +0100 Message-Id: <20240210141913.6611-1-erick.archer@gmx.com> X-Mailer: git-send-email 2.25.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-Provags-ID: V03:K1:Eah5uIlmx1Oy3vyLT4zwqfiQ5COrJpSQE4f6/oguSrE2kY86hdo QIjW/Bs/9Xo0Qm3o7B3tEM/5G1hyC3HQsuMpWJx4b/bdceZiEsEWP/KmpQj1NKIEdPx0G5q 2eeEy4B3+Csbkv9p9lnZCZE+bd2cADA4HhKSh3suTuHxjpueSp6JUsHY9VUhIBjRrnXfh3t 5GbhzX0HiER7+MDJiic/A== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:IhzvHcuJC+E=;GHJKGjSsCANS54bqCQNxN/44ifo 9bqCvzBCyyIV5AAQy8U8INvWJk97jyY8ZGzj7mZTzjWOuOt7smSagbXITxKv4geCA3XJVu4vE 0hYsfu3sWvy3fCNwJ6s6QkBNQb1BTMGw9mwy3poECc1wxqSWYuf3A2VVqwpBlj8slxgsPgQgq syX6sEZDY3swhYf/zAN3socKGOStAUxhxAug7nOsrWmzKpJw/DqVVTEYPq3zH0WRlmTtRHLGA 40Rx8L9wLQSnLQyZHuiMAsCXu4LCM5C+S7xIKwZiYPp/sedY8TnWkTGhhUuamhFaP7mQWSAFx gWIZblydoT47nujdxItHU4Pchxv21B3hn7DV9t2jo/MFke0/tfxG/YgnjFzHxlTcWJgMK/eRj r39nXPlktMP/WGhU9CFgt4RQIjX7+M9oh25lh8MsQG6yLNm/lD/FNsUY7eZ10c1tQYRK9Av6e DTUK7/fyJ1mvHCwAGegKsvH4UjIIAw0cNeuXA5CKV1V24aCR94301qCEqn5Of6CSu+ZlCqx1e Hc8YLjCL6tR8k/xpWHgnbxdWAw+PQXqfj1BMY9G5Cec/Y8eNrTC31fwJne/V5i2C4u3+PpI/I y50J6IUjptVJVwlPulFqoOITs9Qy31YppK2J1pfXkAoC4rRNXMd0nmBFZmF8wP90h9gWAuh3F JIM9kAh9YMRL2r//CFBoB5tqqf7+66erb4WC+idlctJvqdFrqlKSYFdgq30bl5RIpAGiOeKUA Ns8GvXUrIin1O4SSgzRz2gaESJgvPZYFO+dlQOC78cvP5N7jlsHPru14iWXSwJsGTxUbh/AYI 1Th85XbchPMIC00qz2yCW+fCe/5ZJux9ejnMRssskIR/0= This is an effort to get rid of all multiplications from allocation functions in order to prevent integer overflows [1]. As the "q" variable is a pointer to "struct xe_exec_queue" and this structure ends in a flexible array: struct xe_exec_queue { [...] struct xe_lrc lrc[]; }; the preferred way in the kernel is to use the struct_size() helper to do the arithmetic instead of the argument "size + size * count" in the kzalloc() function. This way, the code is more readable and more safer. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-= coded-arithmetic-in-allocator-arguments [1] Link: https://github.com/KSPP/linux/issues/160 [2] Signed-off-by: Erick Archer =2D-- drivers/gpu/drm/xe/xe_exec_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/xe/xe_exec_queue.c b/drivers/gpu/drm/xe/xe_ex= ec_queue.c index bcfc4127c7c5..f4e53cbccd04 100644 =2D-- a/drivers/gpu/drm/xe/xe_exec_queue.c +++ b/drivers/gpu/drm/xe/xe_exec_queue.c @@ -44,7 +44,7 @@ static struct xe_exec_queue *__xe_exec_queue_create(stru= ct xe_device *xe, /* only kernel queues can be permanent */ XE_WARN_ON((flags & EXEC_QUEUE_FLAG_PERMANENT) && !(flags & EXEC_QUEUE_F= LAG_KERNEL)); - q =3D kzalloc(sizeof(*q) + sizeof(struct xe_lrc) * width, GFP_KERNEL); + q =3D kzalloc(struct_size(q, lrc, width), GFP_KERNEL); if (!q) return ERR_PTR(-ENOMEM); =2D- 2.25.1