From patchwork Tue Jul 11 17:17:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 118671 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:6406:b0:135:48c7:ea9a with SMTP id f6csp3274062rwh; Tue, 11 Jul 2023 10:26:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlF+9SzvLC5PPZhyRXTdJnzv/3Cuz3WoTgp7B3nJPoxOPTKADi77k2gGLMFmDm9edLy/AMdf X-Received: by 2002:a05:6a20:2450:b0:132:81a8:1691 with SMTP id t16-20020a056a20245000b0013281a81691mr1616360pzc.46.1689096370132; Tue, 11 Jul 2023 10:26:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689096370; cv=none; d=google.com; s=arc-20160816; b=WeOXlrVbnitiwjWi9Lbu3n1+DbrNIpRPcCO5yHkAdI512mJ3UxbYkDqv49KO+gLqNi A8eLburro9a2TLyiRDqOMrJ31KAQ/G3/Py6bHpU57NnIUw6FLUcFI4i49tZS5mUBnStJ 9WKmNs8gj+57ItVvdWj1dg42gmC/N7JF5gKapTCLPgtLBBzidMK3wbVOBZzl6YTPOk1G ArmZYoyIkzAAD0cmzhXDUrpwGO8pkk4FOBU+fHXdRe4r8GKyHkPmU1osclolZFOMeFHU k2dlTVIVACESx+x67mWfLkfkEiy55sActOH3i++PeR4MYNJms2bdKYjgX7j4mHmFRKmL pBFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OkwnZAXUnxXlGIIXfjo6QLOuqBYji33K6e2hAQN+rq4=; fh=1nNdhl7R87shz8NR0wsonZRuXIWFIMAGTVMiI+iZ2Fo=; b=lTQ7uXV3sgfOTkLZ1xqDReX1eShw7YIT3KEsGiHlveR2nc0CG1h6dCgcqWRXq9bbzR N/rU8YsS359QnZYgCXfFk31Qla4oqGZ8zZRuZEXK8moOgmITiBUwXYZ1P8nXLoeF8eWV ArAU2NUUNS7s2qSSDL4riHjj0Fgbci4Pg7HBN1YXRrFtbYuME1KNFC7rZWLr9nsymKK4 G2ZdpWtQXE/ruTzXdDOwqVydD5D5Ms816jrnBKN+akXg4qeFArL7sxjL6MLWmXDU7chH o0xWYynUqA5qT9VQwNC9LiPjKlH6lq67aJsF82CfuIw+ZlZoIHN+JQxRFhi8ObK7zBxv PtZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dEE0UP0F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g191-20020a6252c8000000b00668705a86ccsi1697458pfb.319.2023.07.11.10.25.56; Tue, 11 Jul 2023 10:26:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dEE0UP0F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233023AbjGKRVl (ORCPT + 99 others); Tue, 11 Jul 2023 13:21:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232653AbjGKRVZ (ORCPT ); Tue, 11 Jul 2023 13:21:25 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 465C01BD7; Tue, 11 Jul 2023 10:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689096046; x=1720632046; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pAWPsjI4cTEbUbFXGBMVoie/XvBSHdTVWugoYwa5pwQ=; b=dEE0UP0Fej6NRF58dz6h5qF+0a1g+R7Gw+uMbSXfJRQ9jRCdGr/Kh8k8 99mpfY/+G8WxCIVhUOo9/zNnsqrUTBYyn5T30NHf3wlWlEqVj9VvgDKFu wlMqUlBsILNxydiyf+kj4NUastzpYcIJuNC6QT4UruXkTKRyAZetwmoJ7 iSYx7FPQAQl2IYw9nF+paTVpqw04QaiNxaDvleYUDz7qKETw6aMl0HQ85 udiA9CvJwgPEOK41tdhhMyPxt6WlOrgdYy5UZRFb8dBI0m1ppLlt62VBQ EmNi6BO5J4NW54gFHkaGWquvA3HaBzus17IdczqOuF29VlpYmWsAWFnlb w==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="362148758" X-IronPort-AV: E=Sophos;i="6.01,197,1684825200"; d="scan'208";a="362148758" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2023 10:19:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="715240943" X-IronPort-AV: E=Sophos;i="6.01,197,1684825200"; d="scan'208";a="715240943" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2023 10:18:04 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 99EF06B9; Tue, 11 Jul 2023 20:17:59 +0300 (EEST) From: Andy Shevchenko To: Mark Brown , Cristian Ciocaltea , Yang Yingliang , Andy Shevchenko , Amit Kumar Mahapatra via Alsa-devel , Serge Semin , Neil Armstrong , Tharun Kumar P , Vijaya Krishna Nivarthi , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-riscv@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Sanjay R Mehta , Radu Pirea , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Tudor Ambarus , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Matthias Brugger , AngeloGioacchino Del Regno , Andy Gross , Bjorn Andersson , Konrad Dybcio , Heiko Stuebner , Palmer Dabbelt , Paul Walmsley , Orson Zhai , Baolin Wang , Chunyan Zhang , Alain Volmat , Maxime Coquelin , Alexandre Torgue , Max Filippov , Steven Rostedt , Masami Hiramatsu , Richard Cochran , Sebastian Reichel Subject: [PATCH v3 09/14] spi: Use struct_size() helper Date: Tue, 11 Jul 2023 20:17:51 +0300 Message-Id: <20230711171756.86736-10-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230711171756.86736-1-andriy.shevchenko@linux.intel.com> References: <20230711171756.86736-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771145915330437663 X-GMAIL-MSGID: 1771145915330437663 The Documentation/process/deprecated.rst suggests to use flexible array members to provide a way to declare having a dynamically sized set of trailing elements in a structure.This makes code robust agains bunch of the issues described in the documentation, main of which is about the correctness of the sizeof() calculation for this data structure. Due to above, prefer struct_size() over open-coded versions. Signed-off-by: Andy Shevchenko --- include/linux/spi/spi.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 21b77bdfac29..35fd61070d9b 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1081,6 +1082,8 @@ struct spi_transfer { * @state: for use by whichever driver currently owns the message * @resources: for resource management when the spi message is processed * @prepared: spi_prepare_message was called for the this message + * @t: for use with spi_message_alloc() when message and transfers have + * been allocated together * * A @spi_message is used to execute an atomic sequence of data transfers, * each represented by a struct spi_transfer. The sequence is "atomic" @@ -1133,6 +1136,9 @@ struct spi_message { /* List of spi_res reources when the spi message is processed */ struct list_head resources; + + /* For embedding transfers into the memory of the message */ + struct spi_transfer t[]; }; static inline void spi_message_init_no_memset(struct spi_message *m) @@ -1193,16 +1199,13 @@ static inline struct spi_message *spi_message_alloc(unsigned ntrans, gfp_t flags { struct spi_message *m; - m = kzalloc(sizeof(struct spi_message) - + ntrans * sizeof(struct spi_transfer), - flags); + m = kzalloc(struct_size(m, t, ntrans), flags); if (m) { unsigned i; - struct spi_transfer *t = (struct spi_transfer *)(m + 1); spi_message_init_no_memset(m); - for (i = 0; i < ntrans; i++, t++) - spi_message_add_tail(t, m); + for (i = 0; i < ntrans; i++) + spi_message_add_tail(&m->t[i], m); } return m; }