From patchwork Fri Nov 8 16:46:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrizio Castro X-Patchwork-Id: 11235267 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 399201599 for ; Fri, 8 Nov 2019 16:46:56 +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 210B42178F for ; Fri, 8 Nov 2019 16:46:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 210B42178F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bp.renesas.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 72A34E9C; Fri, 8 Nov 2019 16:46:55 +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 CD032E9B for ; Fri, 8 Nov 2019 16:46:53 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp2.linuxfoundation.org (Postfix) with ESMTP id 44D081DDD9 for ; Fri, 8 Nov 2019 16:46:53 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.68,282,1569250800"; d="scan'208";a="31199306" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 09 Nov 2019 01:46:52 +0900 Received: from fabrizio-dev.ree.adwin.renesas.com (unknown [10.226.36.196]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id CC50340A6D62; Sat, 9 Nov 2019 01:46:50 +0900 (JST) From: Fabrizio Castro To: cip-dev@lists.cip-project.org Date: Fri, 8 Nov 2019 16:46:49 +0000 Message-Id: <1573231609-25023-1-git-send-email-fabrizio.castro@bp.renesas.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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: Biju Das , JohnsonCH.Chen@moxa.com Subject: [cip-dev] [RFT/RFC linux-4.4.y-cip v2] gpiolib: Fix bad of_node pointer 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: , MIME-Version: 1.0 Sender: cip-dev-bounces@lists.cip-project.org Errors-To: cip-dev-bounces@lists.cip-project.org 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 --- 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 | 5 ++++- 2 files changed, 5 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..820e3e3d 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,9 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) chip->data = data; + if ((!chip->of_node) && (chip->dev)) + chip->of_node = chip->dev->of_node; + spin_lock_irqsave(&gpio_lock, flags); if (base < 0) {