Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8948980ybi; Wed, 10 Jul 2019 02:10:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzmTh7PEryp55ukHHSZ9Emk560+OdBtvmfSiCqO0+4NSy66W6prRL3gFO2GdJqTOJU9Xp8 X-Received: by 2002:a17:902:7088:: with SMTP id z8mr31681489plk.125.1562749814619; Wed, 10 Jul 2019 02:10:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562749814; cv=none; d=google.com; s=arc-20160816; b=QK1PNNEAfzLoAmuRNdHi1Q1ySQLJN9LVHVfYnO6OYHv/7KVz9AjMCZgZtulR/GuC8J xALoXdVCOW3/QK3ZGndresmVy03uJFZ+Sjq8BPc4U3Rbu6mIsWzS3o1QJEPOUEAb7JU9 dMPVYN4N24FQ/XuJ9OkfS7jwkY6HijEJDw6RNxao4VObDXYcCSmIpLjfutAa+fb4s5ca TwaC6+uxPUhHbc9+4XYghpi3kYwpzb7dkwUuX3a8DIFG8i9Jj4qD9FaQLE9iy0rbrAfk dzfq0TNCREMDnPbE3iw1+kM32yhDINUrJ+IVM+IiVQWDsrcy9tV3u/IppkvjsJjDoBpb ykHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=32ir8BoyHUApgZIdTE/QpJVn9dg1MJ7QifLyluzaJtg=; b=GJNCkQPTJIHRjy4AbfcMUwmYmNyHLAck3rrBJIn7U/ozHvCXCd7DQlQ3dG1d89U8QA 8mFUSKcuirXXdoM+3QHVzBMDsHkYfwiUsbt4fBKtnox9b2hgBYoOJhb//BdPJpWc+otT rM6ejxhajBghtPQFkgESFZRlQ/m/NS7cfglkASUf4B3uOWOus7VeEehViZDZkrwyesvJ W+/7u5wTBXwAoyTlYf+qgZ0YkkEjdpPbeuzVI+JAm1FL0JQYHtIHvL2vlLAxkDKaU9JJ 0dRIkHcDJtERJVrY1wUVoh8wUn8B2GWktkU6/PlRJDP90z6kRsh3EL/mhdxvKkS5CXQS gPcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=iG2dLcma; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z6si1658592plo.193.2019.07.10.02.09.58; Wed, 10 Jul 2019 02:10:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=iG2dLcma; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727720AbfGJJI7 (ORCPT + 99 others); Wed, 10 Jul 2019 05:08:59 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37609 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727636AbfGJJI7 (ORCPT ); Wed, 10 Jul 2019 05:08:59 -0400 Received: by mail-wm1-f67.google.com with SMTP id f17so1423346wme.2 for ; Wed, 10 Jul 2019 02:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=32ir8BoyHUApgZIdTE/QpJVn9dg1MJ7QifLyluzaJtg=; b=iG2dLcmapWgTGUjHBg8ecVV631PEaBJxae3t8aI6ryIN9o4MvjnMv7fXHbC4okbWiL LoPW8zq2a7rI1Dt+SYkFu6U6MGGXKEbUCy28TYXx1dcZSAM21LCDkkYIKyvYiBs4fBTz M8SSpSukIP0Qzm6fGOpwL3l4YWwYyoU7i6Iim+szA1QsDf5Ar4lapJ/8rSrv52cki9aP HzqVEHbJHdUiPB9QK01pI6TshGZPrGO0rz6SG6dm8YfK18VlJLzI2xXasm2SbMEEcl4/ M43DykhARgXvGbQcRoS1mwHgYzABmEtkUSVAC6Jxu93bxJnyhPvzYsF2ookuIwJ/XGcn pRlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=32ir8BoyHUApgZIdTE/QpJVn9dg1MJ7QifLyluzaJtg=; b=VUQ01pVLI0Sx6KDZ0Cmq3g2CIGmq/NI5zZCaacSTgTm9xnyrHCe/45qqKF+OvxhhSx mDmL4UlYkHzqfLzh2IUVe9i8zuV8Mbk9Pc8Rc0cxO9KwZDrJb9GatDvhUZQOvxhxZ3pn ARcOnlkdPS+MXqDH5Cktqb3xuE6/+nU4ADRyBOI/aEf/KOvLxZsPAbqZx/m1VBIevOuC oaETLXcAEql4Q/EcYrvUS6caBRX6FebWRTZ4DfO7I+/BrGDEZeO2YkQQChtn9vkZ++db JmJUh2WyZxH7pfSjUIFzkOQ400QoGViHe45UyDUwvFhlcmpDQr2LtkqGR3XKpZ3jAI50 gjsg== X-Gm-Message-State: APjAAAUviDEuivDXKaoafF6ot6Jj/+u/VVajkjQD17+CILMcpwjJD9n+ YeIQQTLbrK+hsg7BCEot3CC8RA== X-Received: by 2002:a1c:cb43:: with SMTP id b64mr4118488wmg.135.1562749736681; Wed, 10 Jul 2019 02:08:56 -0700 (PDT) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id u186sm2308511wmu.26.2019.07.10.02.08.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jul 2019 02:08:56 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , stable@vger.kernel.org Subject: [PATCH 1/2] gpio: em: remove the gpiochip before removing the irq domain Date: Wed, 10 Jul 2019 11:08:51 +0200 Message-Id: <20190710090852.9239-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski In commit 8764c4ca5049 ("gpio: em: use the managed version of gpiochip_add_data()") we implicitly altered the ordering of resource freeing: since gpiochip_remove() calls gpiochip_irqchip_remove() internally, we now can potentially use the irq_domain after it was destroyed in the remove() callback (as devm resources are freed after remove() has returned). Use devm_add_action() to keep the ordering right and entirely kill the remove() callback in the driver. Reported-by: Geert Uytterhoeven Fixes: 8764c4ca5049 ("gpio: em: use the managed version of gpiochip_add_data()") Cc: stable@vger.kernel.org Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-em.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c index b6af705a4e5f..c88028ac66f2 100644 --- a/drivers/gpio/gpio-em.c +++ b/drivers/gpio/gpio-em.c @@ -259,6 +259,13 @@ static const struct irq_domain_ops em_gio_irq_domain_ops = { .xlate = irq_domain_xlate_twocell, }; +static void em_gio_irq_domain_remove(void *data) +{ + struct irq_domain *domain = data; + + irq_domain_remove(domain); +} + static int em_gio_probe(struct platform_device *pdev) { struct em_gio_priv *p; @@ -333,39 +340,32 @@ static int em_gio_probe(struct platform_device *pdev) return -ENXIO; } + ret = devm_add_action(&pdev->dev, + em_gio_irq_domain_remove, p->irq_domain); + if (ret) { + irq_domain_remove(p->irq_domain); + return ret; + } + if (devm_request_irq(&pdev->dev, irq[0]->start, em_gio_irq_handler, 0, name, p)) { dev_err(&pdev->dev, "failed to request low IRQ\n"); - ret = -ENOENT; - goto err1; + return -ENOENT; } if (devm_request_irq(&pdev->dev, irq[1]->start, em_gio_irq_handler, 0, name, p)) { dev_err(&pdev->dev, "failed to request high IRQ\n"); - ret = -ENOENT; - goto err1; + return -ENOENT; } ret = devm_gpiochip_add_data(&pdev->dev, gpio_chip, p); if (ret) { dev_err(&pdev->dev, "failed to add GPIO controller\n"); - goto err1; + return ret; } return 0; - -err1: - irq_domain_remove(p->irq_domain); - return ret; -} - -static int em_gio_remove(struct platform_device *pdev) -{ - struct em_gio_priv *p = platform_get_drvdata(pdev); - - irq_domain_remove(p->irq_domain); - return 0; } static const struct of_device_id em_gio_dt_ids[] = { @@ -376,7 +376,6 @@ MODULE_DEVICE_TABLE(of, em_gio_dt_ids); static struct platform_driver em_gio_device_driver = { .probe = em_gio_probe, - .remove = em_gio_remove, .driver = { .name = "em_gio", .of_match_table = em_gio_dt_ids, -- 2.21.0