From patchwork Mon Mar 4 16:04:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 209628 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1525713dyc; Mon, 4 Mar 2024 08:18:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW/MFsVDjwtmDMzSvflHG59CDlpsG+xvCXFN6I6pWHt5uAGrLkPcnhsW5LAZ3eXZY/C8B+tyhfnjv/cTSVwb5Pvf9wwcw== X-Google-Smtp-Source: AGHT+IHjK62zhOSfD3OG2cR/avlBH2bgdtWmFKtyL3t9E2tKPM9d5/xXWRPygPY5I+YFv3QDwhIR X-Received: by 2002:a05:6a20:e608:b0:1a1:568d:b4eb with SMTP id my8-20020a056a20e60800b001a1568db4ebmr934005pzb.39.1709569102156; Mon, 04 Mar 2024 08:18:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709569102; cv=pass; d=google.com; s=arc-20160816; b=DLn2KXsizuYqfN4WTebopK+03/KGV8Y3eTWRXMwVz9xJ3LKUrmppgumlL89bG3SmuG E1x7MD5t8e/yeqHsrYViJhRvK3vR5Q/wVHNglkNeMaTKoWcMrycpxgQ40DQhKbNctOJA zKbSapBwUDr+NJ8X1xnssFRc+Ps6dDR822LQwKKLEHNcl8fDPOuKSuxt9eJA2y/WvdbW Zu7LslSs9wLsgv90Eecq8+svNKpVEMWWxQpgIhSlB5CofyVp8r5sUZsTk4g3oRXsIbWw TUL5JAAtbcV4YSePY7bjl97eqJERQBdJnqghXJBjet+b15+R/lUgShKi9hTHH04uacG+ epSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JCP8eJQPKeVzox/Qa6ATJPu9ofpJI+UjARSHWwbkYKs=; fh=E8Ig0C35BcRQBXxQQXIUp/23W4GaAxUZxsJgnSUhVe0=; b=0oAJ0zekWzVKNmEvf2V/J1Gd9f/2sEmwsSZJ65w5MmAZ9cnydYIm9+2xauwWPNkLzx DfaeZjwuJVvgyXVh2BJ6GOrBzxfu1VMjLGZsVme7H3OUlSMPE5ozCbhOv9Vp0PHOQlAc xDtcS3mnx+bscFAsmP1afkzKTK2GOt9vWXgJoWDhkP/ATS7lUbuVbLKoMM8nzk/L+teQ u1UA/UUgLcae8NVfIAGw3FFyKhJ/V3yb7uBzW0wm+/qkj0kATgExp/hoFxwkH3FiyrQS DnURRUTR0T47AJMBeoJ9F0CNxDWFaUUEWhuviGWqFfQveLgm3LkVS3ZR2gmnOzxsN+n6 oLrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=kMgmySUD; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-90901-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90901-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p4-20020a056a0026c400b006e4da39134dsi8394119pfw.28.2024.03.04.08.18.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 08:18:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90901-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=kMgmySUD; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-90901-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90901-ouuuleilei=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B49192826D3 for ; Mon, 4 Mar 2024 16:07:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 404744C618; Mon, 4 Mar 2024 16:07:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="kMgmySUD" Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3107482D3 for ; Mon, 4 Mar 2024 16:06:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709568417; cv=none; b=Xu75FYJwMSlLjeoyfNJfbDzs9WNF0uRgevARCIVo3FLWq0tUMvkd5gv3uTvtPio1fUbLblgpsOYjaHcLFO3F9kce3Foqv/xwpsnr6nHSqI7Qe5mxUsUWaCgpfEbceC/BCRJqkwJanHmpdazer0O4WOM0GbVopWv5XMPN28T7HhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709568417; c=relaxed/simple; bh=Iov+SLQtBZ5UAEb6YDKr9rdAOJnCjM7+0r7ET3OF5dA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pMBtEKjqaC6TVF1/6fr7mZxt/i86IxVnd6ZECD/QpF9CeU/BBZ6CaMW17xPP2Ffhz6E+celfnR7K7uH6OpB/0LvGLRHz5uajRTMXIahL82l6at2VyZiL5zcHeTqwR/hoGbhXVpHy8X80mmEGiMO/LcEaTQK8bcAZRMJy5IR3y0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=kMgmySUD; arc=none smtp.client-ip=209.85.160.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-21fa6e04835so1505894fac.1 for ; Mon, 04 Mar 2024 08:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1709568415; x=1710173215; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JCP8eJQPKeVzox/Qa6ATJPu9ofpJI+UjARSHWwbkYKs=; b=kMgmySUDd6O8PX8aZH+RTbu1pDkEu0602rzF0RZRHJsRu4qGQNunJnnXLtipR3zewS wudzqWiofmjMNNUVMgtY7Rsx1WWgVagTE0fMDXzme2u3vIfkKxhlvA5cqi7c0lXA26uN y0clrAfkJneiS9oRsotjBlVGooQslWkaqL9N0aFqCfHhSzLtDUsRtGnbMuoFBtBQxckU ycpLLjNCitB39uZRl6Ga/3ZFfnuird0GXYSPffj5taiyqoWVAgVtrnChW5VmbdAXkdoP /kQz/bEgW1xySjiGu4oW7LeFAxZOu5M3a+b2ZMDC8fUkInSLsvhEInoAjJ0u/dDt9Ms6 OMDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709568415; x=1710173215; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JCP8eJQPKeVzox/Qa6ATJPu9ofpJI+UjARSHWwbkYKs=; b=X7VdAyfjeYNkFBlIv8UQ7tSLqMOmCsv/7N67dWPZ0fLVkGu6XCoSd+RUtKcIT92d38 fMAiWHYkc6VwjZGp2H9zaWFIbsLpD+X7gSa24k0kSmzzcI9Apzj1mY5oFbqpR5vU/ngF Cy4eNtyE+Qz0+JxRvf0aXPBtsQqED6Vu4Vw2Vm57gVW4Au06YXErO+vWbcSHNrw1GNVy oragYp54LqpBfgVv6VJAOHZm3CCqGJOgVOSDnFB6b82SOt7DxLB4He2FbiEAfB90BFV/ YNEL31IaEeCMPxv3kOk2bjgpl1TqKtdNUV5SL+4H6UqyQAeS0Xbsta1iAonQaPuB5kFE Cy2A== X-Forwarded-Encrypted: i=1; AJvYcCWDl10pYT/235C8vAhDpbZ1AoBQqmujHfSENIQjvRKjG7gmeEz2OMSkpT19AZ8hiCDBr8iduHcLUiqisZeOApQig/0gRtFUWsu52iUe X-Gm-Message-State: AOJu0YyAmjsZQRnfrq8X4GODRCyWfZvJl97NQEPVr2p/klPs+ZjuPJ9Q crZcdCY1990kb40sk3kqvWRxGhdSulUd0ItXT8yxvxORTANlueBZVw/TRn0NvYI= X-Received: by 2002:a05:6870:b526:b0:21e:8afd:65d0 with SMTP id v38-20020a056870b52600b0021e8afd65d0mr10111952oap.52.1709568415111; Mon, 04 Mar 2024 08:06:55 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id lu6-20020a056871314600b00221287ebd03sm83392oac.4.2024.03.04.08.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 08:06:54 -0800 (PST) From: David Lechner To: Mark Brown Cc: David Lechner , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Kees Cook , "Gustavo A. R. Silva" , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v2 2/3] spi: axi-spi-engine: use __counted_by() attribute Date: Mon, 4 Mar 2024 10:04:24 -0600 Message-ID: <20240304-mainline-axi-spi-engine-small-cleanups-v2-2-5b14ed729a31@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240304-mainline-axi-spi-engine-small-cleanups-v2-0-5b14ed729a31@baylibre.com> References: <20240304-mainline-axi-spi-engine-small-cleanups-v2-0-5b14ed729a31@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792613041650890195 X-GMAIL-MSGID: 1792613130718024148 This adds the __counted_by() attribute to the flex array at the end of struct spi_engine_program in the AXI SPI Engine controller driver. The assignment of the length field has to be reordered to be before the access to the flex array in order to avoid potential compiler warnings/errors due to adding the __counted_by() attribute. Suggested-by: Nuno Sá Signed-off-by: David Lechner Reviewed-by: Kees Cook --- v2 changes: * Reordered assignment of length field. --- drivers/spi/spi-axi-spi-engine.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index d89f75170c9e..a8f626165f44 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -75,7 +75,7 @@ struct spi_engine_program { unsigned int length; - uint16_t instructions[]; + uint16_t instructions[] __counted_by(length); }; /** @@ -115,9 +115,10 @@ struct spi_engine { static void spi_engine_program_add_cmd(struct spi_engine_program *p, bool dry, uint16_t cmd) { - if (!dry) - p->instructions[p->length] = cmd; p->length++; + + if (!dry) + p->instructions[p->length - 1] = cmd; } static unsigned int spi_engine_get_config(struct spi_device *spi)