From patchwork Mon Mar 4 16:04:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13580834 Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) (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 3D3AA482F3 for ; Mon, 4 Mar 2024 16:06:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709568417; cv=none; b=rkfafIwOUHp9q1IJrW0B2Y2AnImPyip9yEZqOJmzVNZQAdMqmY+d+LxCELcR7rm3moBvNqZlpVIWN5ThWSxJyEcihRIzXSD/y3q6DBclsDV4WJ/V+y/Y+mST0bA6VJuExisH6/mSoQTte99l+H/ESj31Caa+kU8tSCDaDPohJI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709568417; c=relaxed/simple; bh=5hT5wjsUvej4t0PzrwkFZZddS5utw/QYaLNNX9eOC0g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bf+ral9f+oB8k2zrFQ2OV836gC/cp1wdrUVMhPgTwOY+cXW9F2OfBVx35EVK6fjblhqB/flx2kYE3xOA/Jdnf6tgatb9UpYC0v9s/+fJCfTA/spWaCqMVDGuNzODmHV05y9OG4+Xhd4r0iDv+6WnFcujmhCAWXb8aUvZTiHXv1c= 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=ojILu51K; arc=none smtp.client-ip=209.85.160.42 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 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="ojILu51K" Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-21e45ece781so3481464fac.0 for ; Mon, 04 Mar 2024 08:06:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1709568414; x=1710173214; 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=47S4ZgnBYo9jKRg+1Qx0IpWuTU4W29awdHsHBhIR8G8=; b=ojILu51KDxcLa8wt1MuvwAZ2zY0s/ZInPDn+TrUK5FsoZzwbXRJdUlVEgu9z4czUXm /XNS6Eyqxw2xa11MkN2Fn8w1mJdPgPqTH2NWyrNGddt8UjFpB8si9zCM9xVY52D3VMYY rWTA7E5TXy89VWoBTs5KmQkkkkKwMZYYEmR2K37Xy4o/t7JEMtqCkqtCFahzYYfBnkQp 3zK6rfVRLI0yzWsZ1KLlGTQ9F3RLoXYAdvQm/r/FEosbIFN4NUPfnzwsWjz4+7LGxYpM 0s0DKqrfF21G1/xVQ89lbHPuIG9JqV7oUtTAorFMyEAF5LtEXzrnDqr62iT2RORfUlm+ Hj9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709568414; x=1710173214; 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=47S4ZgnBYo9jKRg+1Qx0IpWuTU4W29awdHsHBhIR8G8=; b=kPPm9spc5oPJp5F2yIY11wkV8Ydf2IQi19aDRoCX6e1GUEVwvAq5RR7drHAhyvfO/s kZao5+OjOtJljBXzofbjq/p8KxpChRyqZiep1HVL7/UsV1MdX/rUklNIF49fcpktbY6o X299a0zUE8ocj/eSKOXUOwrg3ETOH0wdaMvWH7I1qsipfgagpxuNKxLKuY8iQgzF+FWY d/XZX9qZk8TwtqPfHgNdCPWcW+kj74VbtQuWN4y+9E2quDd4r9X88KLreyY+APh72EGy J/EaO6KVkWnK12SwZNFqE19lvTJ1I+W6Ifaf3lA2T1sBHb2Z2XlkKlTvIRqWIOIp7vYi I2gQ== X-Forwarded-Encrypted: i=1; AJvYcCWtVrIVeFJJI44+iMlB7ZIBvz11zq/jHo03mSghD+TiGalaB+D3WBooBPbDiDwSs/LFQsGgAmujQryKW9n19k0gKffK9AaN1SpuVuOH6Bgs X-Gm-Message-State: AOJu0Yzns4ivGzbaF5qOl7OHiO2nK1+oeIQrHv/U7AvOnP+ZB7E8WBro 6fDkiq7MkwIQmLvBw6qiyYi2ALA0Su8YEh9Qi+bV5zDTvPS1fLXCsVHeeXyMET0= X-Google-Smtp-Source: AGHT+IHnUujhgYRoulUU9Ki4jG7rgvaQB6rYriALE46IC4meCxLSw11sUvrfGLvhQczpaNuwleJnxw== X-Received: by 2002:a05:6870:37cd:b0:220:9862:a2dc with SMTP id p13-20020a05687037cd00b002209862a2dcmr10440444oai.57.1709568414246; Mon, 04 Mar 2024 08:06:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 08:06:53 -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 1/3] spi: axi-spi-engine: remove p from struct spi_engine_message_state Date: Mon, 4 Mar 2024 10:04:23 -0600 Message-ID: <20240304-mainline-axi-spi-engine-small-cleanups-v2-1-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-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 The program pointer p in struct spi_engine_message_state in the AXI SPI Engine controller driver was assigned but never read so it can be removed. Reviewed-by: Kees Cook Signed-off-by: David Lechner Reviewed-by: Gustavo A. R. Silva --- drivers/spi/spi-axi-spi-engine.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 6177c1a8d56e..d89f75170c9e 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -82,8 +82,6 @@ struct spi_engine_program { * struct spi_engine_message_state - SPI engine per-message state */ struct spi_engine_message_state { - /** @p: Instructions for executing this message. */ - struct spi_engine_program *p; /** @cmd_length: Number of elements in cmd_buf array. */ unsigned cmd_length; /** @cmd_buf: Array of commands not yet written to CMD FIFO. */ @@ -543,7 +541,6 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, /* reinitialize message state for this transfer */ memset(st, 0, sizeof(*st)); - st->p = p; st->cmd_buf = p->instructions; st->cmd_length = p->length; msg->state = st; 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: 13580835 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) (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 F304E4778E for ; Mon, 4 Mar 2024 16:06:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709568417; cv=none; b=bcxz4h1eKfLWVdzgwHwSC/2KriwNlIRpGqn/Jt8azxdWFR7tjqnEe8iME+5UUDXYo8ZZHPd7ORVK4toqS3EgLr2Mb8I5N6dAWoBPCqLHpZ8EfuMAiDLZXU9ycvZlM9xzeyKPjKjVdTjG0qp3uqTiMJUK/Ix1HTtLThFiWsUGfgE= 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.49 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 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: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-21fa6e04835so1505895fac.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=NAiK22dLoCWC9qRASjD0o3UVqGFhmSBketUyKOFCcz92K1jd5eD3ZNkqONqVHQBcpf tWrUF6a2OGet/guMw3uV3YyVlArKmJcrlhi8Xs+nNZwXzNlyvKiLMMRQBBTJxM7w4ZHi Z16y2I3bPSi8E/j6cDWbJPRmiUKzOPRUCtNYNU5ZvYvfzeLkDpLlWiiZ0KD2VdXfqIeo xVp82F/YYz3B5fhh0g6iCqBouQeVHiKeSbr/RG0VSlWWJujMV/bKwExId9SN8hJONxt9 H0VdG0dNzp/s32iK3lUKsq92OEJFjf4CJrsbsIlGsZWRxkRiPxHb31jPqoH7EinnPGVT 1zig== X-Forwarded-Encrypted: i=1; AJvYcCUrTfyQ42ls5m4QYcQkI4hzF4McjIrZJRxlyOokB1pFN5kdcb/Zo+MryMMmGktcIqe/v9yXKHw8Ab50X8NPr5QVGtXZ4srz6tOutgJIK2dG X-Gm-Message-State: AOJu0YxSEdUt+eF+y3l4KNsSsTtNRGpEv7ngVYLamygyAoyDqBzXx7hi nwofvFx+6v094DkWAlK28eeyuVTVPq82ErpeD0qlwKSU5blgOQBvwR92G9gCwaM= X-Google-Smtp-Source: AGHT+IHdqhPGLcqP8KvM0oEOY4dxrGT/0OINH0urzsMtnq4EMXL6ZM/tA2tvq5C6ZZ2itfpQXPu/MA== 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-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 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: Gustavo A. R. Silva 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) From patchwork Mon Mar 4 16:04:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13580836 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.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 C1E0C487BC for ; Mon, 4 Mar 2024 16:06:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709568418; cv=none; b=kNg1VIQxIeoUnvmBJx3x4KPz30rW0XQtYxX4nP8VA3nIla4Ym6UYc9p75NwyZDqYypc5zufJtgGgch74wdWho5sLYbQOuSlYadOdtVotE4s/oPvgOYW8FVzmXpV7IJtDTxzExu//SIGdYHeg7IEFzGvV/el0udAN78NxYQDEtq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709568418; c=relaxed/simple; bh=HDTEIEeTth+YlarlZwpbtqNSffqitQLrinmgPBP7yu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OpU9UR5tQLrmZYVkDIYMIgrPVW16wxuVgT5stO5clZqdaQXLC/E7GZTXkMQ5iUwHcUFdfdEY/4cuCAlYjqSGrR5vPY62p0j65Q1BZDjyeOjkuze8zTLIzWEt8OELXLGtyArTNFFdcz9m65NpujykAzEi1iaHzhMuEAAQI1MWsRw= 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=HIh9XJsY; arc=none smtp.client-ip=209.85.210.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 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="HIh9XJsY" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-6e2c45b81d8so1508650a34.0 for ; Mon, 04 Mar 2024 08:06:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1709568416; x=1710173216; 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=yn3BxlJjgBPLtIhw8+vZTdHKWgVz7bubHMhhj+7dA28=; b=HIh9XJsYBqEMYRZ8eqTP1tlbkwygZg35Z15NyWUUL9pqFI+K7BC8nxqaRJCUP4bTYa fJNFOGfr89S6ZL1dr12WqBLdhoRmjg0PRO0L/Z/tc5HgQB0DA59XtGE5yZKpLjA720Ll kTNbBKV90lMMKndvzQ1EJU5DFWuP4+mZ+UivCTHTfN2yywKjzrNayUQh/+JfvQeQYHO3 tdlRTiY6oiycYraN+2Pa97OQEmeseynPpZ6Zk2HfrkQ/Hij0uByIY0JQivFE0eVqJnUo geRetPZWlRrrs22mfqNq862Lw3xhLMKRbg4K9Dg/1zkvr3BVU/X37m3NOYBtGT7c5ixA GXag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709568416; x=1710173216; 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=yn3BxlJjgBPLtIhw8+vZTdHKWgVz7bubHMhhj+7dA28=; b=moeEFgHAzGSunqD2IsH7WxSWIU8aVi1CEm3EkkpsH8IEx2Gx0cd3wOOO82+RRdCNXu 6kfAcB8V5BseBjlgYdHOt8ai7ptfl18HYHtPvVuKTptuSUT1B5w/7M4mTKiXYFVeCidW B1ZPW1vriJk68zGkJkRcXisIF5np6lPR5NS6+zwvb6J5tNtBk+FswLKA1LoXYjlQ3Y4A Jgn3PoMdGqmrZTq/v7OzYsLZ/ozZqm8xJv4BUEnkzaPemWsVDnK8fUCtV9Dvv1vmByje mYiFBO4JL7t02egBYyq27ZMe4ibbAb/uJPAe+YOqIOgLxu1/WAs25BlRoMijM0OrdshD tzJA== X-Forwarded-Encrypted: i=1; AJvYcCXDKIwsYVjHsQucdec7Fl/cSxtR/7TplP9cVJWZCUampFuFR2FakgZyHL2zOSdi0fwQe43VV9G8P35eCS57RlniHzNiGmSyTN6xdYJGLKNo X-Gm-Message-State: AOJu0YxUZODfLpjuzrCN+r7eWdlVuTQqARte7VcZwn6TxIAoqjZkqn0r hvKXK25NnDnht8v8JmJi7rVXeB9lRVPcoxlPiyqv5JGIvC1jJxpy+emDolyRrcJsyIXrmSSZ+Ff 9 X-Google-Smtp-Source: AGHT+IEf31u9H/Myq6t1QuUwWolHTsna+Q0D0Xy9VLu1SozYg1bm/W09fH44eW599tqlHTEORQ0BUQ== X-Received: by 2002:a05:6870:55d2:b0:220:c434:385b with SMTP id qk18-20020a05687055d200b00220c434385bmr4105937oac.0.1709568415975; 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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 08:06:55 -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, Christophe JAILLET Subject: [PATCH v2 3/3] spi: axi-spi-engine: use struct_size() macro Date: Mon, 4 Mar 2024 10:04:25 -0600 Message-ID: <20240304-mainline-axi-spi-engine-small-cleanups-v2-3-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-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This makes use of the struct_size() macro to calculate the size of the struct axi_spi_engine when allocating it. Suggested-by: Christophe JAILLET Reviewed-by: Kees Cook Signed-off-by: David Lechner Reviewed-by: Gustavo A. R. Silva --- drivers/spi/spi-axi-spi-engine.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index a8f626165f44..7cc219d78551 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -502,15 +503,13 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) static int spi_engine_optimize_message(struct spi_message *msg) { struct spi_engine_program p_dry, *p; - size_t size; spi_engine_precompile_message(msg); p_dry.length = 0; spi_engine_compile_message(msg, true, &p_dry); - size = sizeof(*p->instructions) * (p_dry.length + 1); - p = kzalloc(sizeof(*p) + size, GFP_KERNEL); + p = kzalloc(struct_size(p, instructions, p_dry.length + 1), GFP_KERNEL); if (!p) return -ENOMEM;