imperfectism / rpms / kernel

Forked from rpms/kernel 4 years ago
Clone
e336be
From patchwork Fri Nov 16 14:39:07 2018
e336be
Content-Type: text/plain; charset="utf-8"
e336be
MIME-Version: 1.0
e336be
Content-Transfer-Encoding: 7bit
e336be
X-Patchwork-Submitter: James Hughes <james.hughes@raspberrypi.org>
e336be
X-Patchwork-Id: 10686407
e336be
Return-Path: 
e336be
 <linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org>
e336be
Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org
e336be
 [172.30.200.125])
e336be
	by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BA9C3CF1
e336be
	for <patchwork-linux-arm@patchwork.kernel.org>;
e336be
 Fri, 16 Nov 2018 14:40:20 +0000 (UTC)
e336be
Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1])
e336be
	by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88C992D04D
e336be
	for <patchwork-linux-arm@patchwork.kernel.org>;
e336be
 Fri, 16 Nov 2018 14:40:20 +0000 (UTC)
e336be
Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486)
e336be
	id 7C6802D0B5; Fri, 16 Nov 2018 14:40:20 +0000 (UTC)
e336be
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
e336be
	pdx-wl-mail.web.codeaurora.org
e336be
X-Spam-Level: 
e336be
X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED,
e336be
	DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1
e336be
Received: from bombadil.infradead.org (bombadil.infradead.org
e336be
 [198.137.202.133])
e336be
	(using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits))
e336be
	(No client certificate requested)
e336be
	by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 02F272D0B9
e336be
	for <patchwork-linux-arm@patchwork.kernel.org>;
e336be
 Fri, 16 Nov 2018 14:40:19 +0000 (UTC)
e336be
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
e336be
	d=lists.infradead.org; s=bombadil.20170209; h=Sender:
e336be
	Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe:
e336be
	List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:
e336be
	Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date:
e336be
	Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:
e336be
	References:List-Owner; bh=q+rr6CTCNe7Aj9DWt6k8ZBDJfuNlw6LK4NEqho/OsL8=; b=slV
e336be
	BxeOcHW4UYDgm2VXfNMIZb+/8LPmzjGPpBpBe5IaMR/NthCsM9AL2A1aGdlPRKp8j/Oimcml9ytBG
e336be
	vy3/u46ZlKFd5bAYEl5veGalWXzUg1KN7UhADmXD9fmMOzkFD4fMChA8+g2qK83F6SfqDM0VS3i14
e336be
	/ubAQ9CUdaFi4Vr7F4EZtPdbPmSm76Rm9H8sWxWe6seIEmsL6VMpLVzRLAA0zvX5nslXgUPvDLEZj
e336be
	uk7BIzGfdWU1oB15xwTu8kyp24WrC2Xd/DNCrrIlvBJ6Vn4lvfdqwPT+Xg59IAaibUhoj/fq1HNet
e336be
	QenokEPTxg7SS3FsAKl96cR5mWeudtg==;
e336be
Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org)
e336be
	by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux))
e336be
	id 1gNfI9-0007DF-JA; Fri, 16 Nov 2018 14:40:17 +0000
e336be
Received: from casper.infradead.org ([2001:8b0:10b:1236::1])
e336be
 by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux))
e336be
 id 1gNfI4-00075P-2l
e336be
 for linux-arm-kernel@bombadil.infradead.org; Fri, 16 Nov 2018 14:40:12 +0000
e336be
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
e336be
 d=infradead.org; s=casper.20170209; h=Message-Id:Date:Subject:Cc:To:From:
e336be
 Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:
e336be
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
e336be
 Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id:
e336be
 List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive;
e336be
 bh=0v+Gt0Sb75ntX3ncvTo0T5q/LQ9HrDko5y0UEkZ6WVk=; b=SCmdpUIYIRr3Gb8eXMDGHl/os
e336be
 AVmLBMIQEbA1mUB4WPQJlUjz7NKtNXgtLQxSY+yiwIb+LrripAgbQ6yK1Vkn+4bmhtSkb97glmraT
e336be
 bMOZKrRj/cPhxW5osOa0o2BJQRqWqignWxy8539dbxXbpAAKW+12jA+dOqrjOFUftFH7geD4Ttwis
e336be
 y/j75BOi7ObkcK1mBDyJDNuSEt2CZutCNZ+A7v7/zqkxnhS3hS7Y9hUD81+J+cIu5x103POH6i7FC
e336be
 7JazaqnBZYtl66kXXPOs62v3HA96/QLz7CxmdsnNQvw28MNKsxLw5TKnXJUDJmDCybQ5FL6k6Xomg
e336be
 T9PDZO9+g==;
e336be
Received: from mx08-00252a01.pphosted.com ([91.207.212.211])
e336be
 by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux))
e336be
 id 1gNfHz-0006AE-RY
e336be
 for linux-arm-kernel@lists.infradead.org; Fri, 16 Nov 2018 14:40:09 +0000
e336be
Received: from pps.filterd (m0102629.ppops.net [127.0.0.1])
e336be
 by mx08-00252a01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id
e336be
 wAGEcLBT000897
e336be
 for <linux-arm-kernel@lists.infradead.org>; Fri, 16 Nov 2018 14:39:55 GMT
e336be
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.org;
e336be
 h=from : to : cc : subject : date : message-id; s=pp;
e336be
 bh=0v+Gt0Sb75ntX3ncvTo0T5q/LQ9HrDko5y0UEkZ6WVk=;
e336be
 b=ynWh6Gt8VRIRTTbVy4Q9U7IsJWRMWYUNzTD1MYt8M2mcj01ElaCuktcZdGoRxGBJXjLU
e336be
 CYJP75gWsuHHvbSWSSn2l+qpGuEHm+ddFXuMB4nxC5VmQokt/Z0KPScc4Na2IOOU1Ci/
e336be
 wUg2tPdhfupkGIPzTt32SXu3pQX4aAYqx0AEaeJ3ptU/223MOj2Z40HZui1SL0yHxdsT
e336be
 283+7DokK0bontWXs0j69cFVklLF+txi0untOXTxGuvtbzj0vu6uMErB9qhph6HVKlnH
e336be
 kwaoGLPYrc0JnmZt1Kx7nmAQ+xxE3RaNA7E/IisHqX9m5C57JAMtN6WdWUTaLjWeIs8n 2Q==
e336be
Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com
e336be
 [209.85.128.70])
e336be
 by mx08-00252a01.pphosted.com with ESMTP id 2nr7cnhbky-1
e336be
 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK)
e336be
 for <linux-arm-kernel@lists.infradead.org>; Fri, 16 Nov 2018 14:39:55 +0000
e336be
Received: by mail-wm1-f70.google.com with SMTP id d26-v6so24770633wmb.4
e336be
 for <linux-arm-kernel@lists.infradead.org>;
e336be
 Fri, 16 Nov 2018 06:39:55 -0800 (PST)
e336be
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
e336be
 d=raspberrypi.org; s=google;
e336be
 h=from:to:cc:subject:date:message-id;
e336be
 bh=0v+Gt0Sb75ntX3ncvTo0T5q/LQ9HrDko5y0UEkZ6WVk=;
e336be
 b=TFhWj6OD0WYvVWhFc0RE+UyQKaAMuO0Da2ahzvPlkfTJj3d26Mf15Ai4ipbfJy4x9d
e336be
 RLlgEH8Vj457x2kK3QmlXDC5Cy+kzp6FiZi2aFSBinKjY06Dmt4LElzlaye8szk/IuJ/
e336be
 f6HdjG3Rmt6Ys/Kx8fct+p87NyvHNe/yfCGnUj5k1nz7+m2eApkvTkGxzYe5SXn5s1Jp
e336be
 nv/30o4+CcPFK3SqAWo+GkWgD/Uae+4gCP38KxLx6dsYxCS7/kqIF46ac9WmAx9k44Jz
e336be
 Wt18Pe1A7rIj38vRwLv2JuwUkZrOlAhav52EyDM/03QbgRKzEM9En5DYV2GFAqR1Xc3w
e336be
 qLzw==
e336be
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
e336be
 d=1e100.net; s=20161025;
e336be
 h=x-gm-message-state:from:to:cc:subject:date:message-id;
e336be
 bh=0v+Gt0Sb75ntX3ncvTo0T5q/LQ9HrDko5y0UEkZ6WVk=;
e336be
 b=gFrGygir8lioHrOeF0abzZ3xbTuyQEnk7F/vaRJmx5SyMuxe5SQqcM/PozflvPaB4w
e336be
 wHeng0ewo0t6S/xfZo9EpTKB19L5L5XnrxLoseo+tagkZJkCH2Bcw7dsBzALR2upGwrT
e336be
 SfHywXMeCKH9fRAu3/Hj0W934lZDwMG3xqmWWebQ/wqDBE41Nk/dl9iHnGKp9QN61uee
e336be
 Qv0jpp3sglzprI5CIEQqkElIXAF/jjnPqbknf+5nUyH4xUoe+CzTaEldVeHFc4iTerOZ
e336be
 b48uPgriPJVTq7Gr7L8qWJ5yLZWqenG4sAIpLbanD8Mkw8ogaybVfIZyzrSKoTbtBiSa
e336be
 oOEg==
e336be
X-Gm-Message-State: AA+aEWaOCOYCkmegm7N2wWsL8XdrnmJenH+HXps2b21WEUnrWH3tCofP
e336be
 O07nsIq/s30FFJwtMB9dMCaWwCmc2iSWxn7hnqFhagZMyuYFYcJ1Zs5caqAV/LcSS/BBriTI4M7
e336be
 4RALk0oVU/TiJvemnTTRSwFul6+hCHLFRxRM=
e336be
X-Received: by 2002:a1c:1cc4:: with SMTP id
e336be
 c187-v6mr2937585wmc.75.1542379194749;
e336be
 Fri, 16 Nov 2018 06:39:54 -0800 (PST)
e336be
X-Google-Smtp-Source: 
e336be
 AFSGD/XjyVsHsmDi+oKxMsFZ/hLG36TQdg1uDC2wO1upiuvyI+72rZz3AeAffzu3LWvkW8xxAI1e0w==
e336be
X-Received: by 2002:a1c:1cc4:: with SMTP id
e336be
 c187-v6mr2937565wmc.75.1542379194454;
e336be
 Fri, 16 Nov 2018 06:39:54 -0800 (PST)
e336be
Received: from jamesh-VirtualBox.pitowers.org
e336be
 ([2a00:2381:fdf7:14:4419:8784:6076:3820])
e336be
 by smtp.gmail.com with ESMTPSA id a7sm26247594wrx.26.2018.11.16.06.39.53
e336be
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
e336be
 Fri, 16 Nov 2018 06:39:53 -0800 (PST)
e336be
From: James Hughes <james.hughes@raspberrypi.org>
e336be
To: eric@anholt.net, stefan.wahren@i2se.com,
e336be
 linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org
e336be
Subject: [PATCH v3] firmware: raspberrypi: Fix firmware calls with large
e336be
 buffers
e336be
Date: Fri, 16 Nov 2018 14:39:07 +0000
e336be
Message-Id: <20181116143907.6149-1-james.hughes@raspberrypi.org>
e336be
X-Mailer: git-send-email 2.17.1
e336be
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, ,
e336be
 definitions=2018-11-16_09:, , signatures=0
e336be
X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 
e336be
X-CRM114-CacheID: sfid-20181116_144007_971248_9AC931E8 
e336be
X-CRM114-Status: GOOD (  21.12  )
e336be
X-BeenThere: linux-arm-kernel@lists.infradead.org
e336be
X-Mailman-Version: 2.1.21
e336be
Precedence: list
e336be
List-Id: <linux-arm-kernel.lists.infradead.org>
e336be
List-Unsubscribe: 
e336be
 <http://lists.infradead.org/mailman/options/linux-arm-kernel>,
e336be
 <mailto:linux-arm-kernel-request@lists.infradead.org?subject=unsubscribe>
e336be
List-Archive: <http://lists.infradead.org/pipermail/linux-arm-kernel/>
e336be
List-Post: <mailto:linux-arm-kernel@lists.infradead.org>
e336be
List-Help: <mailto:linux-arm-kernel-request@lists.infradead.org?subject=help>
e336be
List-Subscribe: 
e336be
 <http://lists.infradead.org/mailman/listinfo/linux-arm-kernel>,
e336be
 <mailto:linux-arm-kernel-request@lists.infradead.org?subject=subscribe>
e336be
Cc: James Hughes <james.hughes@raspberrypi.org>
e336be
MIME-Version: 1.0
e336be
Content-Type: text/plain; charset="us-ascii"
e336be
Sender: "linux-arm-kernel" <linux-arm-kernel-bounces@lists.infradead.org>
e336be
Errors-To: 
e336be
 linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org
e336be
X-Virus-Scanned: ClamAV using ClamSMTP
e336be
e336be
Commit a1547e0bca51 ("firmware: raspberrypi: Remove VLA usage")
e336be
moved away from VLA's to a fixed maximum size for mailbox data.
e336be
However, some mailbox calls use larger data buffers
e336be
than the maximum allowed in that change. This fix therefor
e336be
moves from using fixed buffers to kmalloc to ensure all sizes
e336be
are catered for.
e336be
e336be
There is some documentation, which is somewhat out of date,
e336be
on the mailbox calls here :
e336be
https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
e336be
e336be
Fixes: a1547e0bca51 ("firmware: raspberrypi: Remove VLA usage")
e336be
e336be
Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
e336be
Reviewed-by: Eric Anholt <eric@anholt.net>
e336be
---
e336be
 drivers/firmware/raspberrypi.c | 35 +++++++++++++++++-----------------
e336be
 1 file changed, 18 insertions(+), 17 deletions(-)
e336be
e336be
v2: Changes to commit message and format only. No code change.
e336be
v3: Moved declaration of header back to original position
e336be
e336be
diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
e336be
index a200a2174611..44eb99807e33 100644
e336be
--- a/drivers/firmware/raspberrypi.c
e336be
+++ b/drivers/firmware/raspberrypi.c
e336be
@@ -14,6 +14,7 @@
e336be
 #include <linux/module.h>
e336be
 #include <linux/of_platform.h>
e336be
 #include <linux/platform_device.h>
e336be
+#include <linux/slab.h>
e336be
 #include <soc/bcm2835/raspberrypi-firmware.h>
e336be
 
e336be
 #define MBOX_MSG(chan, data28)		(((data28) & ~0xf) | ((chan) & 0xf))
e336be
@@ -21,8 +22,6 @@
e336be
 #define MBOX_DATA28(msg)		((msg) & ~0xf)
e336be
 #define MBOX_CHAN_PROPERTY		8
e336be
 
e336be
-#define MAX_RPI_FW_PROP_BUF_SIZE	32
e336be
-
e336be
 static struct platform_device *rpi_hwmon;
e336be
 
e336be
 struct rpi_firmware {
e336be
@@ -144,28 +143,30 @@ EXPORT_SYMBOL_GPL(rpi_firmware_property_list);
e336be
 int rpi_firmware_property(struct rpi_firmware *fw,
e336be
 			  u32 tag, void *tag_data, size_t buf_size)
e336be
 {
e336be
-	/* Single tags are very small (generally 8 bytes), so the
e336be
-	 * stack should be safe.
e336be
-	 */
e336be
-	u8 data[sizeof(struct rpi_firmware_property_tag_header) +
e336be
-		MAX_RPI_FW_PROP_BUF_SIZE];
e336be
-	struct rpi_firmware_property_tag_header *header =
e336be
-		(struct rpi_firmware_property_tag_header *)data;
e336be
+	struct rpi_firmware_property_tag_header *header;
e336be
 	int ret;
e336be
 
e336be
-	if (WARN_ON(buf_size > sizeof(data) - sizeof(*header)))
e336be
-		return -EINVAL;
e336be
+	/* Some mailboxes can use over 1k bytes. Rather than checking
e336be
+	 * size and using stack or kmalloc depending on requirements,
e336be
+	 * just use kmalloc. Mailboxes don't get called enough to worry
e336be
+	 * too much about the time taken in the allocation.
e336be
+	 */
e336be
+	void *data = kmalloc(sizeof(*header) + buf_size, GFP_KERNEL);
e336be
 
e336be
+	if (!data)
e336be
+		return -ENOMEM;
e336be
+
e336be
+	header = data;
e336be
 	header->tag = tag;
e336be
 	header->buf_size = buf_size;
e336be
 	header->req_resp_size = 0;
e336be
-	memcpy(data + sizeof(struct rpi_firmware_property_tag_header),
e336be
-	       tag_data, buf_size);
e336be
+	memcpy(data + sizeof(*header), tag_data, buf_size);
e336be
+
e336be
+	ret = rpi_firmware_property_list(fw, data, buf_size + sizeof(*header));
e336be
+
e336be
+	memcpy(tag_data, data + sizeof(*header), buf_size);
e336be
 
e336be
-	ret = rpi_firmware_property_list(fw, &data, buf_size + sizeof(*header));
e336be
-	memcpy(tag_data,
e336be
-	       data + sizeof(struct rpi_firmware_property_tag_header),
e336be
-	       buf_size);
e336be
+	kfree(data);
e336be
 
e336be
 	return ret;
e336be
 }