From patchwork Fri Sep 14 08:36:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 969684 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xs4all.nl Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42BTQN5Cthz9s3l for ; Fri, 14 Sep 2018 18:36:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727865AbeINNuJ (ORCPT ); Fri, 14 Sep 2018 09:50:09 -0400 Received: from lb3-smtp-cloud8.xs4all.net ([194.109.24.29]:51309 "EHLO lb3-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727716AbeINNuJ (ORCPT ); Fri, 14 Sep 2018 09:50:09 -0400 Received: from [192.168.2.10] ([212.251.195.8]) by smtp-cloud8.xs4all.net with ESMTPA id 0jahgsqXOxO9B0jakgbSXx; Fri, 14 Sep 2018 10:36:42 +0200 To: "open list:GPIO SUBSYSTEM" , Linus Walleij , Ludovic Desroches From: Hans Verkuil Subject: [PATCH] gpiolib: check if irqchip already has the irq hook replacements Message-ID: Date: Fri, 14 Sep 2018 10:36:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Language: en-US X-CMAE-Envelope: MS4wfOPFUeKV7kRrPpc9qdL20XMIYHNbxq2bq3XUkoJSSyIQXr6jCtDs/xyq++5p7rK76YKT81BVsKvKosB4nvzvqFWMF0wxAjFZiABDJMa1/bRB2cP+0BeX M/nrvUe4sUyr64b6QbTsA0vgmnZ4YL9pq9s5OKwx6gHphbZYKD9QpH4chXN3CqHC9ljgsfL0Tcq/LgpEfa4dQKAgcXCBld1Qkce7XLAx1qp+WJNtfbw5NPae bJhVvA9Ls63qlzEmGiGpVg== Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Some drivers use a single irqchip for multiple gpiochips. As a result the irqchip hooks are overridden for the first gpiochip that was added, but for the other gpiochip instances this should not happen again, otherwise we would go into an infinite recursion. Check for this, but also log a message that the driver should be fixed since this is bad practice. Signed-off-by: Hans Verkuil Tested-by: Ludovic Desroches Tested-by: Guenter Roeck --- Ludovic, can you test this with your unmodified driver? In particular I'd like to see how many of these messages you get and how they look like in the kernel log. I think you should get 4 of these messages. Thanks! Hans --- diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index efce534a269b..a29c917b459f 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1859,6 +1859,16 @@ static void gpiochip_set_irq_hooks(struct gpio_chip *gpiochip) } if (WARN_ON(gpiochip->irq.irq_enable)) return; + /* Check if the irqchip already has this hook... */ + if (irqchip->irq_enable == gpiochip_irq_enable) { + /* + * ...and if so, give a gentle warning that this is bad + * practice. + */ + chip_info(gpiochip, + "detected irqchip that is shared with multiple gpiochips: please fix the driver.\n"); + return; + } gpiochip->irq.irq_enable = irqchip->irq_enable; gpiochip->irq.irq_disable = irqchip->irq_disable; irqchip->irq_enable = gpiochip_irq_enable;