From patchwork Wed Aug 26 11:43:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Chen X-Patchwork-Id: 7076181 Return-Path: X-Original-To: patchwork-linux-mediatek@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 69C42C05AC for ; Wed, 26 Aug 2015 11:44:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7ABBC205C7 for ; Wed, 26 Aug 2015 11:44:26 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 987482053A for ; Wed, 26 Aug 2015 11:44:25 +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 1ZUZ7x-00082G-1E; Wed, 26 Aug 2015 11:44:25 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZUZ7u-0007on-Pn; Wed, 26 Aug 2015 11:44:23 +0000 X-Listener-Flag: 11101 Received: from mtkhts09.mediatek.inc [(172.21.101.70)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 2104824830; Wed, 26 Aug 2015 19:43:40 +0800 Received: from mtksdtcf10.mediatek.inc (10.21.12.150) by mtkhts09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 14.3.181.6; Wed, 26 Aug 2015 19:43:39 +0800 From: Henry Chen To: Mark Brown Subject: [PATCH] regmap: Fix the null function of format_val on regmap_bulk_read. Date: Wed, 26 Aug 2015 19:43:16 +0800 Message-ID: <1440589396-696-1-git-send-email-henryc.chen@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150826_044423_064806_E6D9675A X-CRM114-Status: GOOD ( 15.78 ) X-Spam-Score: -1.1 (-) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, henryc.chen@mediatek.com, linux-mediatek@lists.infradead.org, Sascha Hauer , Matthias Brugger , eddie.huang@mediatek.com, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 The regmap_format will not be initialize if device driver not declare the regmap_bus when registering the regmap. To avoid the null function of format_val when called regmap_bulk_read(). It need to give a format function when regmap init. Signed-off-by: Henry Chen --- I ran into this bug when testing Matthias' v4.2-next/for-next branch on mt8173. It now crashes on boot. The commit [0], which added the call to map->format.format_val from regmap_bulk_read() when map->bus == NULL. [0] commit 15b8d2c41fe5839582029f65c5f7004db451cc2b Author: Arun Chandran mvista.com> regmap: Fix regmap_bulk_read in BE mode Please see the error below, thanks. Call trace: [< (null)>] (null) [] mtk_rtc_read_time+0x9c/0x134 [] __rtc_read_time.isra.3+0x40/0x7c [] rtc_read_time+0x34/0x58 [] __rtc_read_alarm+0x20/0x37c [] rtc_device_register+0x194/0x2e0 [] mtk_rtc_probe+0xf8/0x18c [] platform_drv_probe+0x48/0xc4 [] driver_probe_device+0x188/0x29c [] __driver_attach+0x98/0xa0 [] bus_for_each_dev+0x54/0x98 [] driver_attach+0x1c/0x28 [] bus_add_driver+0x1c0/0x228 [] driver_register+0x64/0x130 [] __platform_driver_register+0x5c/0x68 [] mtk_rtc_driver_init+0x14/0x20 [] do_one_initcall+0x88/0x1ac [] kernel_init_freeable+0x158/0x1fc [] kernel_init+0xc/0xd8 --- drivers/base/regmap/regmap.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 7111d04..9357186 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -607,13 +607,13 @@ struct regmap *regmap_init(struct device *dev, map->reg_write = config->reg_write; map->defer_caching = false; - goto skip_format_initialization; + goto simple_format_initialization; } else if (!bus->read || !bus->write) { map->reg_read = _regmap_bus_reg_read; map->reg_write = _regmap_bus_reg_write; map->defer_caching = false; - goto skip_format_initialization; + goto simple_format_initialization; } else { map->reg_read = _regmap_bus_read; } @@ -783,8 +783,22 @@ struct regmap *regmap_init(struct device *dev, map->defer_caching = true; map->reg_write = _regmap_bus_raw_write; } +/* + * For bulk read, need to hook the format function. + */ +simple_format_initialization: -skip_format_initialization: + switch (config->val_bits) { + case 8: + map->format.format_val = regmap_format_8; + break; + case 16: + map->format.format_val = regmap_format_16_native; + break; + case 32: + map->format.format_val = regmap_format_32_native; + break; + } map->range_tree = RB_ROOT; for (i = 0; i < config->num_ranges; i++) {