From patchwork Fri Nov 8 11:59:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm9obnNvbiBDSCBDaGVuICjpmbPmmK3li7Mp?= X-Patchwork-Id: 11234609 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3AEC313BD for ; Fri, 8 Nov 2019 12:02:37 +0000 (UTC) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F124E2085B for ; Fri, 8 Nov 2019 12:02:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=Moxa.onmicrosoft.com header.i=@Moxa.onmicrosoft.com header.b="dO1P7FGO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F124E2085B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=moxa.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=cip-dev-bounces@lists.cip-project.org Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id BF5DA13B6; Fri, 8 Nov 2019 11:59:46 +0000 (UTC) X-Original-To: cip-dev@lists.cip-project.org Delivered-To: cip-dev@mail.linuxfoundation.org Received: from smtp2.linuxfoundation.org (smtp2.linux-foundation.org [172.17.192.36]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 368C313B6 for ; Fri, 8 Nov 2019 11:59:46 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from APC01-PU1-obe.outbound.protection.outlook.com (mail-eopbgr1320082.outbound.protection.outlook.com [40.107.132.82]) by smtp2.linuxfoundation.org (Postfix) with ESMTPS id 0B0EF1DAA7 for ; Fri, 8 Nov 2019 11:59:42 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VuQBDR8U1q9Dzc/JG3OiqQ+fX02kVVFxff25RcDKwh9Wr64F9p01QQE2lHoOxeAWPnRiVVlKoVu1dps1n2FpbZU5vQHHIj2IHWK/BFPSLVJOZadCY9SSryuoQXLvsQ6BOPRba/PaEB46GZyLbi9tzkccWLJz1Xq/I0AXvtNCy+RL9e2BzJM/8TNGG71IVViV/9dZXOVI0F2RjeSk56V9ehJXGFAns+jsHpbygigESZbCYYwLKJlvTXC1NuzJA+pKc94ZnAyG6bZ8C1Z3WbBVhcwgE7m1k86zmT1I1BcG9t6ejc8Sgwqq1qA7cl/c3WWAZIGKQbf+APP1/Nfc/M65mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0oNWvOsVyxaZOBxJT7Hz2tHQxUr1Iz+4z20EBWY7V/Q=; b=UGe9r5hMxKCPCh7d+vx8P1HIIYiCmqRf7w8uGKqh7IMZXnU+x8+Mn0xDcaHaCybZAlukiDzasUKLV4+lNoBRnNp+TAjU47jDOUjvciFgpyLnuJ8IVZT8gII9NKBp0+Iovi6zeSrMRswilLdbnxgklBAY4a14uhYivoPiPABkdCCwjX/fbCX5jUvvJVjmT7EBx3am4c1v9IF4i/w8kHlvDdeauYIKMMxDR95qh4+iy0t4KIh4yoAOmy7eQD6uQqBmJYo38ryZsj1zqOYOaWWDOfD2WD8TLK9RBXOO54M+crsQUIB6c4LqliMUG5Kh8+mO9IUQS/qeSqKXO5d0uXLWkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=moxa.com; dmarc=pass action=none header.from=moxa.com; dkim=pass header.d=moxa.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Moxa.onmicrosoft.com; s=selector2-Moxa-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0oNWvOsVyxaZOBxJT7Hz2tHQxUr1Iz+4z20EBWY7V/Q=; b=dO1P7FGO4F+hWrST0Js9RspouJlRgt2YLPbK0xaniGmN0hSl8Od7/z1Ptf7oEjc4HkKYJJFPgEpW4KUQsg7+tRqfN+8+DbabPohpA3F5OXNZ9syXaPwWdivyu5rCgekIPUe+LtbE+/ezDBt9WqffRNhpJgA30U7PtTHzg63vyRs= Received: from HK0PR01MB3521.apcprd01.prod.exchangelabs.com (52.132.237.22) by HK0PR01MB2659.apcprd01.prod.exchangelabs.com (20.177.166.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.22; Fri, 8 Nov 2019 11:59:40 +0000 Received: from HK0PR01MB3521.apcprd01.prod.exchangelabs.com ([fe80::80fb:4790:3aa0:8a90]) by HK0PR01MB3521.apcprd01.prod.exchangelabs.com ([fe80::80fb:4790:3aa0:8a90%3]) with mapi id 15.20.2430.023; Fri, 8 Nov 2019 11:59:40 +0000 From: =?utf-8?b?Sm9obnNvbiBDSCBDaGVuICjpmbPmmK3li7Mp?= To: "fabrizio.castro@bp.renesas.com" Thread-Topic: [cip-dev] [PATCH] gpiolib: Support 'gpio-reserved-ranges' property Thread-Index: AdWWKaHwNGeeyHBSSF6m/U0E/pnpeA== Date: Fri, 8 Nov 2019 11:59:40 +0000 Message-ID: Accept-Language: zh-TW, en-US Content-Language: zh-TW X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=JohnsonCH.Chen@moxa.com; x-originating-ip: [122.146.92.136] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b69adf58-93b3-477e-778b-08d7644322dc x-ms-traffictypediagnostic: HK0PR01MB2659: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:773; x-forefront-prvs: 0215D7173F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(136003)(376002)(396003)(39850400004)(366004)(346002)(189003)(199004)(2906002)(81166006)(33656002)(186003)(52536014)(6436002)(8936002)(256004)(14454004)(476003)(74316002)(14444005)(99286004)(26005)(81156014)(8676002)(86362001)(25786009)(2351001)(76116006)(71190400001)(71200400001)(66476007)(55016002)(3846002)(6116002)(790700001)(7736002)(66446008)(6506007)(9686003)(85182001)(66946007)(64756008)(66556008)(6306002)(7696005)(478600001)(6916009)(102836004)(316002)(5660300002)(54896002)(4326008)(486006)(5640700003)(2501003)(66066001); DIR:OUT; SFP:1101; SCL:1; SRVR:HK0PR01MB2659; H:HK0PR01MB3521.apcprd01.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: moxa.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: P90ujeGmUBG2U17sv+uET40MATiszWRCwlPkZbEm/86uo6DAgzemHYciCODwLe20ygQDBaSl4QiP5HNu9/o6Bv1LC0pq6fDIeu3SpCQHVywgV7tBFocWz+aISphgJWaSDVo1Q9e7kf7/ZFafaOBtymRheJJ06JkB6z+oPRcFO5AomFwuWxm1mQmTpxDnl1eaXgBx/UN/lQYfsdReMcr2wjl6ydNFvWFB9f6YPJ3kc4Rpqa+9/hbVpeLIeIFyDkQzNolHO3L9KAtIe786v/sdIm7MUT1EYlMnI8YfEnzRR9JMkp2tRXunUlUhHFtt6qhdI65GjuCP2PNJ27oLW02V6GYFjccgB8QWsmOa+KerP9fAByqWffhNbkUL+vGg3z6Fqw6Xt1A2N/FG8vDN3p0O344GgLAc4HtN0TcR/5OwzSd7yDsZ33nz2gE9D+eQsVH2 x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: moxa.com X-MS-Exchange-CrossTenant-Network-Message-Id: b69adf58-93b3-477e-778b-08d7644322dc X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Nov 2019 11:59:40.5615 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5571c7d4-286b-47f6-9dd5-0aa688773c8e X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: alaks9txIqNtkrIlWuWXorrz7umokM+M75XSAhEmpde4+edqlxM5zEHLfqTxasU7UPXrDc+i4VrvO57fs9TGKQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK0PR01MB2659 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HTML_MESSAGE, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp2.linux-foundation.org Cc: "cip-dev@lists.cip-project.org" Subject: [cip-dev] [PATCH] gpiolib: Support 'gpio-reserved-ranges' property X-BeenThere: cip-dev@lists.cip-project.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: cip-dev-bounces@lists.cip-project.org Errors-To: cip-dev-bounces@lists.cip-project.org Hi Fabrizio Castro, I find a kernel panic issue by gpio when I upgrade kernel to 4.4.182-cip34 with Freescale LS1021A (gpiochip is mpc8xxx series): Kernel log shows “Unable to handle kernel NULL pointer dereference at virtual address 000000b4.” Subsequently, I find the commit baff4777cdb80256cd24dede2a3d0af761356307 (gpiolib: Support 'gpio-reserved-ranges' property) could result in kernel panic because the code “*np= chip->dev->of_node” is executed when chip->dev is NULL: +++ b/drivers/gpio/gpiolib-of.c +static void of_gpiochip_init_valid_mask(struct gpio_chip *chip) +{ + int len, i; + u32 start, count; + struct device_node *np = chip->dev->of_node; + + len = of_property_count_u32_elems(np, "gpio-reserved-ranges"); + if (len < 0 || len % 2 != 0) + return; + + for (i = 0; i < len; i += 2) { + of_property_read_u32_index(np, "gpio-reserved-ranges", + i, &start); + of_property_read_u32_index(np, "gpio-reserved-ranges", + i + 1, &count); + if (start >= chip->ngpio || start + count >= chip->ngpio) + continue; + + bitmap_clear(chip->valid_mask, start, count); + } +}; + Device node of platform will put in gpio chip when of_mm_gpiochip_add() is executed: int of_mm_gpiochip_add(struct device_node *np, struct of_mm_gpio_chip *mm_gc) { int ret = -ENOMEM; struct gpio_chip *gc = &mm_gc->gc; ….. mm_gc->gc.of_node = np; } It’s seems chip->of_node is good. Thanks, Johnson diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 5fe34a9df3e6..ec642bf1d976 100644 --- a/drivers/gpio/gpiolib-of.c diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index adb474089733..487a86495163 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -292,6 +292,43 @@ static unsigned long *gpiochip_allocate_mask(struct gpio_chip *chip) return p; } +static int gpiochip_init_valid_mask(struct gpio_chip *gpiochip) +{ +#ifdef CONFIG_OF_GPIO + int size; + struct device_node *np = gpiochip->dev->of_node; + + size = of_property_count_u32_elems(np, "gpio-reserved-ranges"); + if (size > 0 && size % 2 == 0) + gpiochip->need_valid_mask = true; +#endif + + if (!gpiochip->need_valid_mask) + return 0; + + gpiochip->valid_mask = gpiochip_allocate_mask(gpiochip); + if (!gpiochip->valid_mask) + return -ENOMEM; + + return 0; +} + Could you help me understand why we need to replaced chip->of_node with chip->dev->of_node? The following two items I try have no kernel panic: 1. For gpio drivers: It’s fine and no kernel panic issue if probe(struct platform_device *pdev) in gpio drivers executes the following codes: struct cpio_chip *gc; gc->dev = &pdev->dev; //Put platform’s dev to gpiochip’s dev, and of_node info in pdev->dev->of_node also put in gpiochip structure. But some gpio drivers doesn’t do this, such as gpio-mpc8xxx.c (mpc8xxx series), and result in kernel panic when use this commit. 2. For gpiolib: //set the following code in gpiolib.c and gpiolib-of.c struct device_node *np = gpiochip->of_node;