From patchwork Wed Oct 11 03:26:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 824190 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BvFZklk7"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=pobox.com header.i=@pobox.com header.b="SMCrRGPN"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yBfYM43VZz9ryT for ; Wed, 11 Oct 2017 14:27:19 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=4jzwR3JLURSybJH2QhcqCYc6waXm5uXamkb+cnrZoPM=; b=BvFZklk79tiI4pUW4+HrnQzMiA gjNFVYUqd0K1yAFx0v+pwwbhFjcYCxjfIxSYXZ8WoURMG9qWPrekzchQxabrUDcwL0LUCGiy/IAG+ SNONUHs/nHfD7SE733Vi9ZSjkM5JoGcIF9NslqXxSGrkUjekyhYeFy0/9oVzRCiQq9v6o7/zaiw5G +92mP/G2gmDimI2uXYW6nKplh/qxRSfCRYCaGzoqvjYUvo1XeQAwjQeS+xh8jsOp3JBa4ipoPc8xD Ag406o0kKUhV7iHQrEFH4TC+GJRsKWJFpK3FZL+WgBQPxZsr4YKH7/Girr/a7izxe2i31nu9jiWex jhQob3gw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e27fs-0002t8-BG; Wed, 11 Oct 2017 03:27:12 +0000 Received: from pb-smtp1.pobox.com ([64.147.108.70] helo=sasl.smtp.pobox.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e27fZ-0002Ln-0G for linux-mtd@lists.infradead.org; Wed, 11 Oct 2017 03:26:56 +0000 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 9356C9F57C; Tue, 10 Oct 2017 23:26:26 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=sasl; bh=O9H5 MiUGdRQlUnrmeIrhsky8wrw=; b=SMCrRGPNs9njqCA5XUGhNk0eL0kkVBK3WaiI TLm83Sx7i4yr7TSorYKT2uktsGPYD5nbv/kZh+0IeNa1WqWEIs4YL0uHqvktk5fF EDqiMFnR/RnP0eQvkFmpDhpUDaN9tKNGebV8ntigb+qoCWs4bFMFYhJVwVfAn/3q iSf0OcQ= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 8AAAE9F578; Tue, 10 Oct 2017 23:26:26 -0400 (EDT) Received: from yoda.home (unknown [137.175.234.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 2631E9F575; Tue, 10 Oct 2017 23:26:26 -0400 (EDT) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id 5FAEF2DA0624; Tue, 10 Oct 2017 23:26:25 -0400 (EDT) From: Nicolas Pitre To: Boris Brezillon Subject: [PATCH 1/5] MTD: mtdram: properly handle the phys argument in the point method Date: Tue, 10 Oct 2017 23:26:17 -0400 Message-Id: <20171011032621.26979-2-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171011032621.26979-1-nicolas.pitre@linaro.org> References: <20171011032621.26979-1-nicolas.pitre@linaro.org> X-Pobox-Relay-ID: F696471A-AE33-11E7-A1A0-8EF31968708C-78420484!pb-smtp1.pobox.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171010_202653_261429_90452B24 X-CRM114-Status: GOOD ( 14.97 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [64.147.108.70 listed in list.dnswl.org] 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mtd@lists.infradead.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When the phys pointer is non null, the point method is expected to return the physical address for the pointed area. In the case of the mtdram driver we have to retrieve the physical address for the corresponding vmalloc area. However, there is no guarantee that the vmalloc area is made of physically contiguous pages. In that case we simply limit retlen to the actually contiguous pages. Signed-off-by: Nicolas Pitre Reviewed-by: Richard Weinberger --- drivers/mtd/devices/mtdram.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c index cbd8547d7a..7dbee8e62f 100644 --- a/drivers/mtd/devices/mtdram.c +++ b/drivers/mtd/devices/mtdram.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,27 @@ static int ram_point(struct mtd_info *mtd, loff_t from, size_t len, { *virt = mtd->priv + from; *retlen = len; + + if (phys) { + /* limit retlen to the number of contiguous physical pages */ + unsigned long page_ofs = offset_in_page(*virt); + void *addr = *virt - page_ofs; + unsigned long pfn1, pfn0 = vmalloc_to_pfn(addr); + + *phys = __pfn_to_phys(pfn0) + page_ofs; + len += page_ofs; + while (len > PAGE_SIZE) { + len -= PAGE_SIZE; + addr += PAGE_SIZE; + pfn0++; + pfn1 = vmalloc_to_pfn(addr); + if (pfn1 != pfn0) { + *retlen = *virt - addr; + break; + } + } + } + return 0; }