From patchwork Thu Dec 5 13:39:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrizio Castro X-Patchwork-Id: 11274761 X-Patchwork-Delegate: iwamatsu@nigauri.org 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 581C2930 for ; Thu, 5 Dec 2019 13:44:49 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 08B4E2464D for ; Thu, 5 Dec 2019 13:44:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08B4E2464D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bp.renesas.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=cip-dev-bounces@lists.cip-project.org Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id C0A8F8828F; Thu, 5 Dec 2019 13:44:48 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BnPmgOJpT3Mr; Thu, 5 Dec 2019 13:44:48 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id F356188280; Thu, 5 Dec 2019 13:44:47 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DC75AC077D; Thu, 5 Dec 2019 13:44:47 +0000 (UTC) X-Original-To: cip-dev@lists.cip-project.org Delivered-To: cip-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 43E99C077D for ; Thu, 5 Dec 2019 13:44:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 32E73255F6 for ; Thu, 5 Dec 2019 13:44:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gFsV6e8qPPAJ for ; Thu, 5 Dec 2019 13:44:45 +0000 (UTC) X-Greylist: delayed 00:05:03 by SQLgrey-1.7.6 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by silver.osuosl.org (Postfix) with ESMTP id 940A722844 for ; Thu, 5 Dec 2019 13:44:45 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.69,281,1571670000"; d="scan'208";a="33350741" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 05 Dec 2019 22:39:40 +0900 Received: from fabrizio-dev.ree.adwin.renesas.com (unknown [10.226.36.196]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id B1C1F400E8E6; Thu, 5 Dec 2019 22:39:38 +0900 (JST) From: Fabrizio Castro To: cip-dev@lists.cip-project.org Date: Thu, 5 Dec 2019 13:39:37 +0000 Message-Id: <1575553177-23044-1-git-send-email-fabrizio.castro@bp.renesas.com> X-Mailer: git-send-email 2.7.4 Cc: Biju Das Subject: [cip-dev] [PATCH linux-4.4.y-cip v3] gpiolib: Fix bad of_node pointer X-BeenThere: cip-dev@lists.cip-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: cip-dev-bounces@lists.cip-project.org Sender: "cip-dev" Not every driver initialises of_node from struct gpio_chip, therefore the replacement of of_node from struct gpio_chip with dev->of_node in the below commit won't work on every platform: baff4777cdb8 ("gpiolib: Support 'gpio-reserved-ranges' property") The final result is that on some platforms the kernel will try to dereference a NULL pointer, with obvious consequences. This patch makes sure the pointer gets initialised before its first usage. Fixes: baff4777cdb8 ("gpiolib: Support 'gpio-reserved-ranges' property") Reported-by: Johnson CH Chen Signed-off-by: Fabrizio Castro --- Hi guys, sorry for the trouble. v2 broke Intel builds (thank you Chris for spotting this), v3 fixes that. Are you happy to replace v2 with v3 on linux-4.4.y-cip? Thanks, Fab v2->v3: * v2 was accessing chip->of_node regardless of CONFIG_OF_GPIO being enabled or not. v3 compiles that out in case CONFIG_OF_GPIO is not enabled. v1->v2: * v1 was for testing purposes only, but no point in sending out a dirty patch, therefore cleaned it up --- drivers/gpio/gpiolib-of.c | 2 +- drivers/gpio/gpiolib.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index ec642bf..6fa1818 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -338,7 +338,7 @@ 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; + struct device_node *np = chip->of_node; len = of_property_count_u32_elems(np, "gpio-reserved-ranges"); if (len < 0 || len % 2 != 0) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d72218f..516498e 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -296,7 +296,7 @@ static int gpiochip_init_valid_mask(struct gpio_chip *gpiochip) { #ifdef CONFIG_OF_GPIO int size; - struct device_node *np = gpiochip->dev->of_node; + struct device_node *np = gpiochip->of_node; size = of_property_count_u32_elems(np, "gpio-reserved-ranges"); if (size > 0 && size % 2 == 0) @@ -360,6 +360,11 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) chip->data = data; +#ifdef CONFIG_OF_GPIO + if ((!chip->of_node) && (chip->dev)) + chip->of_node = chip->dev->of_node; +#endif + spin_lock_irqsave(&gpio_lock, flags); if (base < 0) {