From patchwork Thu Jun 20 21:22:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13706401 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 28D337E572; Thu, 20 Jun 2024 21:22:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718918580; cv=none; b=IK+vPLIi6ydWSyIj/qpUP068wd0A2fZTi42d1SrB3t32md0Ub0W709QH2V5fHpb7S0PM5IINYYnr9NuMbl48PDv/zMPwViDopRJDpn1XS9VxSrVgWPrLMso7dgT0+uOMNGD1fXvjMy3gUc/NXKFGMsQNIAt4ofxsMq16SAASXWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718918580; c=relaxed/simple; bh=lIk21poydkHZA9G6tN8B5DcddOq3+4kRdZcXWZ3eiDw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Kn3kQ2Q3pgT5bgoK+F/rJVRDk/37/BKNU+4BQrF58soeWn8vTS24Iknl4TbO4l45HCPZmDmHeRmwTWcL0G33iIMcapVlJdmrl0XCvWNJDdkR04bNHbH77MDHnv2Qzw9OCF3ekhVSGZr4zbf9hREbyUDc/Xx3R/UUG6cpTsiQwFQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Yvmc7sq8; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Yvmc7sq8" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a6f04afcce1so158304366b.2; Thu, 20 Jun 2024 14:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718918577; x=1719523377; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=neE7INAukEKjE2SAP61WvkGQBYpsrnRiNjBLU4VnvgE=; b=Yvmc7sq83eypaEujZSjM9QXDY6so0uLO5irAyJjxY1bSULvkq5+Cu84HQARvyrUrms 60+MgelzI/YyJqT3n1Lh1T7O7xj2KSQTKzp2xuD7m83GYSo7u4kQOSmW/STD9xB4nd4b VzTK+7zD9J45KPxbk0L2QW/ep5Z2diyiEYud0Ax0BrhXnxS9RUcaazfau0OFw6NMdKP/ dYt0eBxWbVRpe1tCoUi9P8YeMjqCVMmh3XaX852tEEd9s0A94YWhbu65tZCFGyXF8ywi Euo7wNTOTODC8s8cl0QgDaOkQEDDJewW7Ppq8uBbATrq+PioJFlTt9GlnvGYbeoPMZFX GCsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718918577; x=1719523377; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=neE7INAukEKjE2SAP61WvkGQBYpsrnRiNjBLU4VnvgE=; b=WL8xOAM4h+dZircJMWBaRuuqJvVj+HJoy6CRgr2dw7RRL1c5P5O6nel2WTQUdcUOF/ 0qfuOcIhYI/cLwNyErWTUb1Gw++9LlgzRNuBiRVJbLHve35Jmm0Zrdwl1XDoiWUuJ4DA 4sOeu3AbnKKTgkT+9SgFyFLexrboZygrPtvD0I6beyIvQcLcMSADha5RCshgQVl62YGg 5qsI8ux+jtcZJfQglnCPqDi6RIUZBJPIOmVeoylagfRb/UuujKWpOaJp73qmYamJKyUk iQwQ19gXf55CLWmEfYPXjHsbFxDhbtqSIruy05HAp0NP3O/xFieMrzI5niZOGRaDpsdW 4nMg== X-Forwarded-Encrypted: i=1; AJvYcCVh/6lh0F74kllQTqe1gVeq63fw6YJ28NQICn4653IaSAMbttnxty44D+KJqbX1NNBxnwPKoBc6dWYXxGhNEDbVwYU3X6J4HWFA3tGWj4AadavM4fVVZ7JFs54TjEJ8yIzLLtAlO/TqLc0f3tSV X-Gm-Message-State: AOJu0YyS9EtP4iQtLqgx41pJ1eeACGdBMmdBuxlSZ54Nf64O6gJQMZb7 2hUIEF/DmcK44QFOtf86pmowJkFnMlUmlDi1/pwQnRxKCNl30XGArgYl2ROP X-Google-Smtp-Source: AGHT+IHE8ItVOOXbIoL6tYrHXRW76APqXsARzi48ADeaS42ghc3AmYrzBRdZpOM2u20JmJDU/Qzxgg== X-Received: by 2002:a17:906:9c88:b0:a6f:b58f:ae47 with SMTP id a640c23a62f3a-a6fb58fba6emr494986866b.10.1718918576877; Thu, 20 Jun 2024 14:22:56 -0700 (PDT) Received: from [127.0.1.1] (84-115-213-103.cable.dynamic.surfer.at. [84.115.213.103]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6fcf560d82sm10922666b.172.2024.06.20.14.22.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:22:56 -0700 (PDT) From: Javier Carrasco Date: Thu, 20 Jun 2024 23:22:33 +0200 Subject: [PATCH 1/2] mfd: omap-usb-tll: annotate struct usbtll_omap with __counted_by Precedence: bulk X-Mailing-List: linux-omap@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240620-omap-usb-tll-counted_by-v1-1-77797834bb9a@gmail.com> References: <20240620-omap-usb-tll-counted_by-v1-0-77797834bb9a@gmail.com> In-Reply-To: <20240620-omap-usb-tll-counted_by-v1-0-77797834bb9a@gmail.com> To: Tony Lindgren , Lee Jones , Kees Cook , "Gustavo A. R. Silva" Cc: linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1718918573; l=894; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=lIk21poydkHZA9G6tN8B5DcddOq3+4kRdZcXWZ3eiDw=; b=OSYqIWUNEtCTr93tYWr99r1gbCF+xJchXhwy2mfzRxuz1aEP4QRMX8dMQ6kZdSzbRg3pQhOY6 8eNfezEiTx4A3X4pljDQBN4SfsYZr+Nk2lsBMFTVndf+JUSeCeOl+0y X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= Use the __counted_by compiler attribute for the "struct clk *ch_clk[]" flexible array member to improve the results of array bound sanitizers. The comments for the variables are no longer needed as it is now clear what is what. Signed-off-by: Javier Carrasco --- drivers/mfd/omap-usb-tll.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c index b6303ddb013b..a091e5b0f21d 100644 --- a/drivers/mfd/omap-usb-tll.c +++ b/drivers/mfd/omap-usb-tll.c @@ -98,8 +98,8 @@ struct usbtll_omap { void __iomem *base; - int nch; /* num. of channels */ - struct clk *ch_clk[]; /* must be the last member */ + int nch; + struct clk *ch_clk[] __counted_by(nch); }; /*-------------------------------------------------------------------------*/ From patchwork Thu Jun 20 21:22:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13706402 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.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 47556824B3; Thu, 20 Jun 2024 21:23:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718918582; cv=none; b=D43L5jTSpT1Dkwq2v7hmf6PA2y29JmxGsU5USpQkFXaFVBn6LGfeRQa802XozZqiOuE1RNoacjnmbHURAuV/qNwt9RreIJsZroOU34OvY4sOF4STVfsZyfAOpZGjNzCFYiLJkdRUvKbyA5oFh8x/FXRFPsLPzn6XY+M7TbXlhAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718918582; c=relaxed/simple; bh=W3zJRVHu5IEnuNfSbP5xtAFgvUA5i7Y8mIhEvQpuVEQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dS5BJawNp2h8bdAp7D5lpuLQrt9VGdqMSV2IywiKkYlfclPqLxzYQxa1SdaU//V1Cy0SGjn0EpLjNvytggG9n8QQ/bvBQY0Jxu4IXfIOAwUcNwv4NKlBInlKxSaEUQvjCELWzCtJW9vU5qlxOj7guR15CAfwX+0br8NH37KeP2Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ter4azBc; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ter4azBc" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a6f1c4800easo148907866b.3; Thu, 20 Jun 2024 14:23:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718918579; x=1719523379; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=tvJiXFffmlTDfRSrFVguX7jVktah6y3nmFwZHVMfroI=; b=Ter4azBc3dBOsrog6R44Xw104CBIgnwjv421eAGwezktnq4A6WHIuyusOnoMyX1D/a LS+3CDtP8qfmLmEFATRfrhSkwSFsx2TPo4olZleuXd8Ag6uvNFLRajP4ZIlJk+PoGn4S g6oYgX1Xn4ajYouZzdBmNycYGQXFr+DAhV0KrAAQjoaTg6xYCIxzscG+fc9k7ljbMLFV GFPP0eRHGD6wKY6x71nHhly6dn+R4xO36CGJzqLQE0EE3BQvOH9WFRZ8A+cP8oCpPg8h 9VLhy8V6DXuLXqLLNI7IscTnk8z9h6Q91gXethi2T4SNnsG5qM6euDj6sxEUE4WQti/e xu4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718918579; x=1719523379; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tvJiXFffmlTDfRSrFVguX7jVktah6y3nmFwZHVMfroI=; b=WxE5JNdg0QNazuLmKkB3RxnZ55myFFUH9B+xYj6x5zuJu5N0qwb+fmboHu3idhOwdM 9rJkTVNaLiHOJM1sp9usytyXq7lOux2R6sx/wg0Rvm8XPlrtX+pWdft2sXO+II4YJOBt elkYh9nqbdp5pm5f8pPfm/t22GxeYJbcCSBbKaQDQ5Gks5f95Y2MDjshqqrJwfyXYK9p Dzoi7z8q+MYZ28g86NhIQPV94lHNSkwgSZeEuq42/2eu3UQ1wn7ZnEKi2dfaNfeN501S 0LbESjaFjaaYHmEZi9Xm2ujnspNMEcwNV+19Hb3ZRia0ie+UD5NzdNjj5j5A6oZqo3z+ 7rAg== X-Forwarded-Encrypted: i=1; AJvYcCWc5ktDibyxHOfSOO38fbawz0H/z1GZ8pvwZLamkXqUKYRY2o7Ov82JvQBktWyTo4q5Y0Y4GSQwndwzAjpgnjlyjrSHhK4IxZ9cnpgsL1opVmO4+bYvQCFivSzfeKONoyu7rG1fXFT0kaFctuNA X-Gm-Message-State: AOJu0YzT/Uic62yrrAyW1qxgnHV2qyVzTJP5xpt2xGme7fLwo87x+OI2 y0Xnb1T7aBKfkpjnxDE7s1LxHJFLPgYvDtKk89IAy3nKMUqzVUopYgBH7UFX X-Google-Smtp-Source: AGHT+IF3rCfMdHT1ePR2H6IMpVrEBm/ZW9hmVius8u0Q2iSl2WnYiakc8n94b267vNSUUckHNW3glA== X-Received: by 2002:a17:907:c003:b0:a6f:b320:f455 with SMTP id a640c23a62f3a-a6fb320f483mr400964066b.32.1718918578717; Thu, 20 Jun 2024 14:22:58 -0700 (PDT) Received: from [127.0.1.1] (84-115-213-103.cable.dynamic.surfer.at. [84.115.213.103]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6fcf560d82sm10922666b.172.2024.06.20.14.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:22:58 -0700 (PDT) From: Javier Carrasco Date: Thu, 20 Jun 2024 23:22:34 +0200 Subject: [PATCH 2/2] mfd: omap-usb-tll: use struct_size to allocate tll Precedence: bulk X-Mailing-List: linux-omap@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240620-omap-usb-tll-counted_by-v1-2-77797834bb9a@gmail.com> References: <20240620-omap-usb-tll-counted_by-v1-0-77797834bb9a@gmail.com> In-Reply-To: <20240620-omap-usb-tll-counted_by-v1-0-77797834bb9a@gmail.com> To: Tony Lindgren , Lee Jones , Kees Cook , "Gustavo A. R. Silva" Cc: linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1718918573; l=1774; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=W3zJRVHu5IEnuNfSbP5xtAFgvUA5i7Y8mIhEvQpuVEQ=; b=/3IIqNmJEJL76pd+rsFBNB8jBYg347ZcVZxlYSGQKzVT2BnMqAEEA0zfQ8c5jQTxoh/3HMXZm EgVO5Ac5w0fD66ZZMPnIqVLm/lpLzYm8VVSXVmiCOOQxbtk3F5y22OT X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= Use the struct_size macro to calculate the size of the tll, which includes a trailing flexible array. Signed-off-by: Javier Carrasco Reviewed-by: Kees Cook --- The memory allocation used to be carried out in two steps: tll = devm_kzalloc(dev, sizeof(struct usbtll_omap), GFP_KERNEL); tll->ch_clk = devm_kzalloc(dev, sizeof(struct clk *) * tll->nch, GFP_KERNEL); Until commit 16c2004d9e4d ("mfd: omap-usb-tll: Allocate driver data at once") turned that into the current allocation: tll = devm_kzalloc(dev, sizeof(*tll) + sizeof(tll->ch_clk[nch]), GFP_KERNEL); That has surprised me at first glance because I would have expected sizeof(tll->ch_clk[nch]) to return the size of a single pointer, not being equivalent to 'sizeof(struct clk *) * nch'. I might be missing/misunderstanding something here because the commit is not new, and the error should be noticeable. Moreover, I don't have real hardware to test it. Hence why I didn't mark this patch as a fix. I would be pleased to get feedback about this (why it is right as it is, or if that is actually a bug). --- drivers/mfd/omap-usb-tll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c index a091e5b0f21d..5f25ac514ff2 100644 --- a/drivers/mfd/omap-usb-tll.c +++ b/drivers/mfd/omap-usb-tll.c @@ -230,8 +230,7 @@ static int usbtll_omap_probe(struct platform_device *pdev) break; } - tll = devm_kzalloc(dev, sizeof(*tll) + sizeof(tll->ch_clk[nch]), - GFP_KERNEL); + tll = devm_kzalloc(dev, struct_size(tll, ch_clk, nch), GFP_KERNEL); if (!tll) { pm_runtime_put_sync(dev); pm_runtime_disable(dev);