From patchwork Fri Nov 8 16:36:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrizio Castro X-Patchwork-Id: 11235251 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 13B701515 for ; Fri, 8 Nov 2019 16:36: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 B9C1821882 for ; Fri, 8 Nov 2019 16:36:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B9C1821882 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 7DE8CE23; Fri, 8 Nov 2019 16:36:55 +0000 (UTC) X-Original-To: cip-dev@lists.cip-project.org Delivered-To: cip-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 3B21CE23 for ; Fri, 8 Nov 2019 16:36:54 +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 smtp1.linuxfoundation.org (Postfix) with ESMTP id E1A8B196 for ; Fri, 8 Nov 2019 16:36:52 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.68,282,1569250800"; d="scan'208";a="31198953" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 09 Nov 2019 01:36:51 +0900 Received: from fabrizio-dev.ree.adwin.renesas.com (unknown [10.226.36.196]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 833C940A4D47; Sat, 9 Nov 2019 01:36:49 +0900 (JST) From: Fabrizio Castro To: cip-dev@lists.cip-project.org Date: Fri, 8 Nov 2019 16:36:48 +0000 Message-Id: <1573231008-24239-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 smtp1.linux-foundation.org Cc: Biju Das , JohnsonCH.Chen@moxa.com Subject: [cip-dev] [RFT/RFC linux-4.4.y-cip] 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 Reported-by: Johnson CH Chen Signed-off-by: Fabrizio Castro --- Hi Johnson, could you please test this patch on your system? Thanks, Fab drivers/gpio/gpiolib-of.c | 4 +++- drivers/gpio/gpiolib.c | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index ec642bf..36b60dd 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) @@ -445,8 +445,10 @@ int of_gpiochip_add(struct gpio_chip *chip) { int status; + /* if ((!chip->of_node) && (chip->dev)) chip->of_node = chip->dev->of_node; + */ if (!chip->of_node) return 0; diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d72218f..0fd443a 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) @@ -354,12 +354,16 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) int base = chip->base; struct gpio_desc *descs; + descs = kcalloc(chip->ngpio, sizeof(descs[0]), GFP_KERNEL); if (!descs) return -ENOMEM; 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) {