From patchwork Mon Oct 30 18:48:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 117499 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp2987204edm; Mon, 30 Oct 2017 11:50:38 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QDrEHlMLrh2xroGhE1otsugXqqZoX7tg3erKs/Gvv6/sVKZ2MtNhddV+eRAEa7GhWP1657 X-Received: by 10.99.119.199 with SMTP id s190mr8672718pgc.110.1509389438032; Mon, 30 Oct 2017 11:50:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509389438; cv=none; d=google.com; s=arc-20160816; b=i5DiLbCLI/1k9Lc65Jmv6ukhbTN93ewMJFdWkhoy3dLhTfKhJ8ZcoUeW/cGJV+8CYs 7euAdivs/31OB27V12ZKeMouFkw+xiAf15sKBgsZVMac/EKXK/nIsSOGLOvpoLEJNPJ7 YgNJhT8mg5TcWkHEI40PAn0OvTFk96Kii3f7BSP4FyrGUxYAfMvTIF0TbWuL7MhY/JF6 nmNpOQVHwS1LAk2IpZGuGeKNClxqHqYYxi1uw5NWpNDtHA9HOeHeGrA4SmpHlqoCVZ6S ojxUpenMhMj/ptSnHT/Z5j2FbVDFIN6JdH8OBC21f2TuAlJNvKrImadOgZO7fwC3MgpO IlWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature:dkim-signature:arc-authentication-results; bh=cUjyH3chgT4Rb6Y4ozsXtlh5RbiPSHt7GGpCF23O24U=; b=t093sBRxXKsYLgafulEkIw9SNef9jby6GUzCfVM5KRrgVrMIjFQKXrukH8Q28ul9Sx mF74ZV3srVSvoM9uyfHABV6DSftJ1KSFlbS7PcvNMIxcAaeltWtYrEMkMtcgRXuahezU PcIUDxykBN88+kHxax5A6Ghy6oacewtJldTjyVczA0gE106aFA6xp9n2AzCS4LOq6BNt Hu9gPGM2AhTZqn4RYCFhMW6AwK9Hu7IChlscoxnaHzGVnwSmZ96wUDzBo2pYptfHwk8J 40AcmSjK4VIeTkAWZXvk8GnEB/XY2Y+iJFt7czjNG01oBJoJaGZJeq2QadD9CXBG6t9Q eyoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=S+KAuzKD; dkim=neutral (body hash did not verify) header.i=@pobox.com header.s=sasl header.b=SvdWYPZt; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id d2si10434111pgp.817.2017.10.30.11.50.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Oct 2017 11:50:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) client-ip=65.50.211.133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=S+KAuzKD; dkim=neutral (body hash did not verify) header.i=@pobox.com header.s=sasl header.b=SvdWYPZt; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=cUjyH3chgT4Rb6Y4ozsXtlh5RbiPSHt7GGpCF23O24U=; b=S+KAuzKDsvvdHehi4gbWEMJF8Z KBsy1QPYiHPD1Qz2uu8OEs975zyu1TXiTeBYr2XcMqcD/RyXi7gg/RGq73zDhrwHE1lUFq1Icc/yE fR6ODhluVyIbsfVJwtMoZswRuUrnPkcIeX97wAx2keaHjp4rTf5VkSZGvi4OebRVfhiaWRfCRhRtX Cl5+WExso0hmg8Muc4FGmk3X7PVkxZY/Ib3F2HB87rWATuJC/CTuQy8FToptmbQDXWfG1/5DfJCXY 2D0v5dshmLtKmPk7M4W421771i0JG73mWxY6ifA242Me6tYP8K+EYOhyAA3QLYuaJqGESgqHJFxV6 4ouBUSwQ==; 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 1e9F8n-0002IL-0l; Mon, 30 Oct 2017 18:50:29 +0000 Received: from pb-smtp2.pobox.com ([64.147.108.71] helo=sasl.smtp.pobox.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e9F7M-0000Ma-DH for linux-mtd@lists.infradead.org; Mon, 30 Oct 2017 18:49:06 +0000 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 232FFA1E0C; Mon, 30 Oct 2017 14:48:38 -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=Z41H 0cMybL2ws8vzsqddQzpBN9c=; b=SvdWYPZtUrj7Ue0OpTjqox2Xnk8B7gj21onw 5h6scmous0wy5yW4gXKQOWAT9tHEnbKtxXmgn1fwpd932FJdIWNVqP5C9JO8q4WS pDpUufrlJGHQLZkoY3NJ+HEgBUrVYLYsi6HV9+cJ5Q1oqlJ7gbdtWJXEBS5iaisv vlpH0ig= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 1AD04A1E0A; Mon, 30 Oct 2017 14:48:38 -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-smtp2.pobox.com (Postfix) with ESMTPSA id 95C2EA1E04; Mon, 30 Oct 2017 14:48:37 -0400 (EDT) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id BB91B2DA01CE; Mon, 30 Oct 2017 14:48:36 -0400 (EDT) From: Nicolas Pitre To: Boris Brezillon , Richard Weinberger Subject: [PATCH v3 1/5] MTD: mtdram: properly handle the phys argument in the point method Date: Mon, 30 Oct 2017 14:48:29 -0400 Message-Id: <20171030184833.20709-2-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171030184833.20709-1-nicolas.pitre@linaro.org> References: <20171030184833.20709-1-nicolas.pitre@linaro.org> X-Pobox-Relay-ID: F08E4ABA-BDA2-11E7-B572-575F0C78B957-78420484!pb-smtp2.pobox.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171030_114900_703771_E0E7FAF3 X-CRM114-Status: GOOD ( 15.01 ) 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.71 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: Chris Brandt , linux-mtd@lists.infradead.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.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 Acked-by: Boris Brezillon --- drivers/mtd/devices/mtdram.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) -- 2.9.5 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c index cbd8547d7a..4418629e8d 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 = addr - *virt; + break; + } + } + } + return 0; }