Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35593869rwd; Mon, 10 Jul 2023 09:33:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlFZe46j4oidW4j4JgpxHetKLDdsVRdjkWVzBwwYbOU8vIp6j2PUoEtaEscvOwBLSYkXJuv7 X-Received: by 2002:a2e:9a84:0:b0:2b7:1dd:b416 with SMTP id p4-20020a2e9a84000000b002b701ddb416mr10326412lji.15.1689006815967; Mon, 10 Jul 2023 09:33:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689006815; cv=none; d=google.com; s=arc-20160816; b=bK0dV6KAUxCvEqseHuOCi8KYWlfzCEnqDB5Fs6Z3AqmGACFzhqvcyLzQyFgZ+S3qp9 8IiRt7q3AoiPSinp2Qr3+M3fzBvDAyurV5yBcK+Q+QMj+OB5PDIzFuZkgTniD6SnLicf WGLw+HgHdZkIyRechojIwAn1RnFthpMgbNIec0xzSYuLboeaHvyxdPhaRdIjL5rHFjTS cvG7Jc9s6KBU2s7qEVsBEkapsBik8U2D99WQQ6+PJpJ2931nm4Qdm5H34czqyXi96DHu 7ZO1EoT7r9qvz7X6+S5bSh1qOy4M4CS5o8nU0NCdqq2oNIHqwS+awKlLfeu9TbCIn1vc QdRg== 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=TDiXHoYTJnRZnqhsnfThuK4h1+zWj+oTDicnc+AEmQE=; fh=CWfEt6/vd4IsHMc+T8W3bMkH4b5uOoX72TeJSijIGlU=; b=h02rseDrJo7mIo0o0zLeAO9eiFMNjoER0yV2KKnYkwhTFK9Bl23nDVsGkL/03VjgFY lTggBx+EYpUwEYEsyq2t4h0Ty2xt2j8dQ6uxpVEBJ+iuJsfgcAyhyy5LiaH9/Y92/m6f ccPNweYTCrGKmFvxqHGkayQ6wt5oVmfhqjEb8SGGYyVixZCyNHUPyb99L19azBxvQ1f3 6IL06FE32gARZ8RLBFkxYCbiMIgC6yC89SoMDF1p4iA5QjncN6Tz1K5g8xzJWewp5ix4 x5U2qF4mlC2VoqXulWQjIyuKaJdIofhRfEsqWXyNHH2gkLnVnZNXMf1OKHzTCfVdg2BR dzgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EVjOppnU; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a17090668d500b00992f45c9348si9118791ejr.1010.2023.07.10.09.33.11; Mon, 10 Jul 2023 09:33:35 -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=EVjOppnU; 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 S233595AbjGJPuO (ORCPT + 99 others); Mon, 10 Jul 2023 11:50:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbjGJPtw (ORCPT ); Mon, 10 Jul 2023 11:49:52 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79933198; Mon, 10 Jul 2023 08:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689004189; x=1720540189; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2ECimbLN3Odgvy6H4NztBc0veTLSWVtVr1a7U9ECQf8=; b=EVjOppnU7a5dlvJvqS3dje8fQGfbLZRD0ckEl1RuA/6vig4Q5D8x5OPG iNMHq70xQOQVs/EizKV0MSeSd2387kGSjc8Gg3qM1nUtj9i4CCvzSxx2j xDiZJ43l2XO35B9towE7HRIAdWhdwUV2I/A04MX7761a/lJIQ0P08UKW0 OgsQvmhvZdU+Q0XO4tcEGGTNj8KOISz4zHrJeftPaOp1xmeFX73tgIVUt RcZ/lou8FU6w26zuYZ8O6LfZ1lsjMvx8jr0LPX7SUQlzuVCTNxxPsTqdE WV56X5gI2y15/fSMTQ6EUJduSY/9diVJrd4/15RzjHE/0FcMILubZWXEz g==; X-IronPort-AV: E=McAfee;i="6600,9927,10767"; a="361842517" X-IronPort-AV: E=Sophos;i="6.01,194,1684825200"; d="scan'208";a="361842517" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2023 08:49:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10767"; a="720743960" X-IronPort-AV: E=Sophos;i="6.01,194,1684825200"; d="scan'208";a="720743960" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 10 Jul 2023 08:49:36 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id AC4E86B9; Mon, 10 Jul 2023 18:49:34 +0300 (EEST) From: Andy Shevchenko To: Mark Brown , Cristian Ciocaltea , Yang Yingliang , Andy Shevchenko , Amit Kumar Mahapatra via Alsa-devel , Neil Armstrong , Tharun Kumar P , Vijaya Krishna Nivarthi , =?UTF-8?q?Uwe=20Kleine-K=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 , Serge Semin , 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 Subject: [PATCH v2 09/15] spi: Use struct_size() helper Date: Mon, 10 Jul 2023 18:49:26 +0300 Message-Id: <20230710154932.68377-10-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230710154932.68377-1-andriy.shevchenko@linux.intel.com> References: <20230710154932.68377-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 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 c9479badf38c..9fb8efb068c6 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -1095,6 +1096,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" @@ -1147,6 +1150,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) @@ -1207,16 +1213,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; } -- 2.40.0.1.gaa8946217a0b