From patchwork Thu Sep 18 06:03:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Dubey X-Patchwork-Id: 4929281 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9DD93BEEA5 for ; Thu, 18 Sep 2014 06:04:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A4312201B4 for ; Thu, 18 Sep 2014 06:04:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE4832011D for ; Thu, 18 Sep 2014 06:04:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XUUmp-0003kB-4G; Thu, 18 Sep 2014 06:01:47 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XUUml-0003ha-Oc for linux-arm-kernel@lists.infradead.org; Thu, 18 Sep 2014 06:01:44 +0000 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NC300K2V2218SD0@mailout2.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 18 Sep 2014 15:01:13 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.124]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id E1.66.02948.9257A145; Thu, 18 Sep 2014 15:01:13 +0900 (KST) X-AuditID: cbfee68d-f79c46d000000b84-e9-541a75291285 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id AA.1F.04943.9257A145; Thu, 18 Sep 2014 15:01:13 +0900 (KST) Received: from pankajdubey ([107.108.83.134]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NC3008YJ21K9752@mmp2.samsung.com>; Thu, 18 Sep 2014 15:01:13 +0900 (KST) From: Pankaj Dubey To: 'Dong Aisheng' References: <1410935510-1567-1-git-send-email-pankaj.dubey@samsung.com> <20140917085818.GA10285@shlinux1.ap.freescale.net> <000401cfd269$922dfc40$b689f4c0$@samsung.com> <20140918030552.GA26661@shlinux1.ap.freescale.net> In-reply-to: <20140918030552.GA26661@shlinux1.ap.freescale.net> Subject: RE: [PATCH v3] mfd: syscon: Decouple syscon interface from platform devices Date: Thu, 18 Sep 2014 11:33:26 +0530 Message-id: <000701cfd306$4d3e8080$e7bb8180$@samsung.com> MIME-version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-index: AQGAgvNtQpXjUZMClJmM9wWnjoVNAgMenyfbAIibLDoCPoOsEJx1zwVQ Content-language: en-us X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprBKsWRmVeSWpSXmKPExsWyRsSkRlezVCrE4OU6BYu/k46xWzzc2c9i ceDFQhaLZZPuslnMnT2J0eL7ri/sFr0LrrJZ3P96lNGi80IHq8Wmx9dYLS7vmsNmMeP8PiaL 25d5LT4d/c9qcWN6C6tFxzJGi1W7/jBa3Hy2nclByKOluYfN4/evSYweTzZdZPT4d7ifyWPi WV2PnbPusnvcubaHzWPzknqP3uZ3bB59W1YxenzeJBfAHcVlk5Kak1mWWqRvl8CV8WDaVdaC 1eoVMw60sjcwtsp3MXJySAiYSDzsP8oGYYtJXLi3HswWEljKKLF4i38XIwdEzaH4LkYuoPB0 RomHS14wQjh/GS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kmceHe erYuRi4OIYHpjBIPl7xghHD+MkrMmradEaSKTUBX4sn7ucwgtoiApsTzPa9ZQYqYBVpZJJ62 roFqf8gocfL2ChaQKk4Be4kN6y8xgdjCAmESV3vPs4OsZhFQlTi9oxYkzCtgKbFg5z9GCFtQ 4sfke2CtzAJaEut3HmeCsOUlNq95ywxxqoLEjrOvGSGOcJN42vKfEaJGXGLSg4fsExiFZiEZ NQvJqFlIRs1C0rKAkWUVo2hqQXJBcVJ6rqFecWJucWleul5yfu4mRnACeya1g3Flg8UhRgEO RiUe3gO8UiFCrIllxZW5hxglOJiVRHjzfIFCvCmJlVWpRfnxRaU5qcWHGE2BHp3ILCWanA9M rnkl8YbGJuamxqaWJhYmZpZK4rwHWq0DhQTSE0tSs1NTC1KLYPqYODilGhj7v7IxVNS9tZ3H FzzBRbzlmKyF86FVfPxvyw1P65VnLy+wPtRmKyvFYJO376/TgYUXyn70O11xMlEpt24MzVfJ Vr4rl1z37tP7ll7FaY8sszUu11Yrn1nnJFbcfOrLssIdu9znHzK6a27DrsfOYJcg9Xz7sTdn 2Ct0++2mLpZ8r7i8/e8bKSWW4oxEQy3mouJEAGUPAip2AwAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140917_230143_948075_F88B149F X-CRM114-Status: GOOD ( 26.56 ) X-Spam-Score: -5.7 (-----) Cc: 'Boris BREZILLON' , kgene.kim@samsung.com, linux@arm.linux.org.uk, 'Geert Uytterhoeven' , arnd@arndb.de, 'Stephen Warren' , naushad@samsung.com, 'Xiubo Li' , linux-kernel@vger.kernel.org, tomasz.figa@gmail.com, linux-samsung-soc@vger.kernel.org, thomas.ab@samsung.com, vikas.sajjan@samsung.com, chow.kim@samsung.com, joshi@samsung.com, lee.jones@linaro.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, Adding CC to Xiubo Li, Geert Uytterhoeven and Stephen Warren. On Thursday, September 18, 2014, Dong Aisheng wrote, > On Wed, Sep 17, 2014 at 04:50:50PM +0530, Pankaj Dubey wrote: > > Hi, > > > > On Wednesday, September 17, 2014, Dong Aisheng Wrote, > > > > > > > > + regmap = regmap_init_mmio(NULL, base, &syscon_regmap_config); > > > > > > Does a NULL device pointer work? > > > > Yes, it is safe, at least we are able to test on Exynos based SoC. > > I have tested it with kgene/for-next kernel on Exynos3250. > > Also it has been tested on Exynos5250 based Snow board with 3.17-rc5 > > based kernel by Vivek Gautam. > > > > Patch V2 also has been tested by "Borris Brezillon" on AT91 platform. > > > > > > The kernel i tested was next-20140915 of linux-next. > > please see regmap_get_val_endian called in regmap_init function. > static enum regmap_endian regmap_get_val_endian(struct device *dev, > const struct regmap_bus *bus, > const struct regmap_config *config) { > struct device_node *np = dev->of_node; > enum regmap_endian endian; > ... > } > It will crash at the first line of dev->of_node if dev is NULL. > > Can you check if you're using the same code as mine? No, it's not same. My bad that I was not using linux-next for testing this patch. We tested on kgene/for-next where these changes still have not come. Just now I checked linux-next and found that it will crash at first line of "regmap_get_val_endian" as there is no check for NULL on dev. I checked git history of regmap.c file and found recently this file has been modified for adding DT endianness binding support. Following are set of patches gone for this cf673fb regmap: Split regmap_get_endian() in two functions 5844a8b regmap: Fix handling of volatile registers for format_write() chips 45e1a27 regmap: of_regmap_get_endian() cleanup ba1b53f regmap: Fix DT endianess parsing logic d647c19 regmap: add DT endianness binding support. I think there should have been a check for NULL on "dev" in "regmap_get_val_endian", so that if dev pointer exist then only it makes sense to get endianness property from DT. I will suggest following fix in regmap.c for this. With following fix I tested it and it works well on linux-next also. So if you can confirm following fix is working for you then I can post this patch. -------------------------------------------- Subject: [PATCH] regmap: fix NULL pointer dereference in regmap_get_val_endian Recent commits for getting reg endianess causing NULL pointer dereference if dev is passed NULL in regmap_init_mmio. This patch fixes this issue, and allows to parse reg endianess only if dev and dev->of_node exist. Signed-off-by: Pankaj Dubey --- drivers/base/regmap/regmap.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) /* Retrieve the endianness specification from the regmap config */ @@ -487,15 +487,20 @@ static enum regmap_endian regmap_get_val_endian(struct device *dev, if (endian != REGMAP_ENDIAN_DEFAULT) return endian; - /* Parse the device's DT node for an endianness specification */ - if (of_property_read_bool(np, "big-endian")) - endian = REGMAP_ENDIAN_BIG; - else if (of_property_read_bool(np, "little-endian")) - endian = REGMAP_ENDIAN_LITTLE; + /* If the dev and dev->of_node exist try to get endianness from DT */ + if (dev && dev->of_node) { + np = dev->of_node; - /* If the endianness was specified in DT, use that */ - if (endian != REGMAP_ENDIAN_DEFAULT) - return endian; + /* Parse the device's DT node for an endianness specification */ + if (of_property_read_bool(np, "big-endian")) + endian = REGMAP_ENDIAN_BIG; + else if (of_property_read_bool(np, "little-endian")) + endian = REGMAP_ENDIAN_LITTLE; + + /* If the endianness was specified in DT, use that */ + if (endian != REGMAP_ENDIAN_DEFAULT) + return endian; + } /* Retrieve the endianness specification from the bus config */ if (bus && bus->val_format_endian_default) -- Thanks, Pankaj Dubey > Regards > Dong Aisheng > > > > > Thanks, > > Pankaj Dubey > > > > > Regards > > > Dong Aisheng > > > > > > > > > > > > > > > _______________________________________________ > > > > linux-arm-kernel mailing list > > > > linux-arm-kernel@lists.infradead.org > > > > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > > diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index f2281af..455a877 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -477,7 +477,7 @@ static enum regmap_endian regmap_get_val_endian(struct device *dev, const struct regmap_bus *bus, const struct regmap_config *config) { - struct device_node *np = dev->of_node; + struct device_node *np; enum regmap_endian endian;