Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4468141rwb; Mon, 31 Jul 2023 07:21:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlGYuGAq4+zQnFRmu2LHKzVWxPaAF2HM87Ll8hYxSFSmNmuclvkgnfjtC6tI7j6oJe/2z9Yb X-Received: by 2002:a05:6a20:1001:b0:13c:3b5e:a12a with SMTP id gs1-20020a056a20100100b0013c3b5ea12amr8437581pzc.34.1690813274549; Mon, 31 Jul 2023 07:21:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690813274; cv=none; d=google.com; s=arc-20160816; b=Ubj2Lr3dS6nm86IWUsZJJSwRIVz7G2HRysU+13zMXJMCH3J2AbbSTbtsgzwJyoIBvi WxR7sCaz5WivI7mbD+G3l3c8N8tpG0+YFtQm7tdNFmHm8q3GD/eZ16IVr0sGeE1o5XW/ bTlXHx/p/JibGShleJlyl3yDK5aA4gPVDTKYPlVfttaoey77ig4OB0cLPiAcgCjnvxFc PTbxA5KIWVmIsuaxjxBaaTVVuExVeFqnSuBro++U7LDaY9EwnykJrzeEkvkkh2jeaFrx YOgTzGYKrPODqRHS3Zoh2X+iaW6rd1CnYs11rjwRYG1aI9zKJrP8auPaUmWIA/EUdx5C J4IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=OjNUiGbK+r1sXqp9L+BG2Nwgnyi0n65xn60LuBTJ+Lo=; fh=W+dBki0gAtsdynKUnp9cRt34//eqyUngbC6emtOLcOo=; b=sRk05Y6T3RLqqJDK/fJFBuTydRVTIkT6bd1qy/No9M4DDpfb3GpfE16rwlKDwyXYXM XhQw8R9o2LF/UTEWG/6VPg0WZ+2dRxFUg+kDaT0h+J21iS6rKH/6dJj1k/opczOl+EPl Y/IQ81c/Tr1zkVJ4Te6vPMkb7DQzd/OHGAILO+Waa7sIe4+GoV1+FBcE/5ZR2teLNnQ7 9ulxvHDteiKsydfv7aJ59Xanoqx8KkLyEJEeuRLCMsrcsGVq6IIDzOMXLJ7nNOq77EQE FojgnjbonkCQwvA8M/+7SzkJptx6EllvNdeA19KTOBWgBOQex9tp//5aQIlUPX+NQQHS dbnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ipE2GeHm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l25-20020a635b59000000b005640118d203si6638732pgm.193.2023.07.31.07.20.56; Mon, 31 Jul 2023 07:21:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ipE2GeHm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231345AbjGaM7s (ORCPT + 99 others); Mon, 31 Jul 2023 08:59:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230206AbjGaM7q (ORCPT ); Mon, 31 Jul 2023 08:59:46 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D24A210E9 for ; Mon, 31 Jul 2023 05:59:44 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-99c1d03e124so87479166b.2 for ; Mon, 31 Jul 2023 05:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690808383; x=1691413183; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=OjNUiGbK+r1sXqp9L+BG2Nwgnyi0n65xn60LuBTJ+Lo=; b=ipE2GeHmGakEq92kZfr0zFwxnvW8Bm1NtgHlVo+VScWEywfWmiDQZ30e6NG4kzr8Nf l0HE/lQrsj5Jw9gxLxsslNaqp3ue3LjUCFI3vNJ/mtEqCWHys0ED+BtfsA72/y3BZN1t 5NsQiqcsJSsiyrQdFUOpbUGliSd8ViYY+SiE6hZhgqWiIxApRkzMzWxjSB/ZnkMBB6BB PvwHuEHVwhryClOh22M2lQ9jJHEeQYrDD0TzSFip7j8EyukgjkANeivDoC3zFJk9yYLn 9IiFw18Gu7fwb/OswNV5n1JITJ2O+Ia054m+SwYrVGFaZauSsFthBZlaknIg+WZR/+3I dSaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690808383; x=1691413183; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OjNUiGbK+r1sXqp9L+BG2Nwgnyi0n65xn60LuBTJ+Lo=; b=M40lif9YMKC42/0MaRL4QrD46zA8u6U1uZVzXABL4Yh1LUWGff/ge3hDsoyRG9TpRK d0MDtGUf2fjBGkj1rJvJOgad+PaQ3K8DCof0GSNYeKrp7ci/H/CwwpFOLvH7a/0aoQXE cfF1ZypMeFcTxewqbYY7/xFiOnAcMI9pvgJVE8tgyUJQ5IJE0EN2kbJF2IKZGh2/itJN rOEOkldJmyQdmLtWXGz6aX1VYovLh4Gydls7dBlUgC4uK7wgBtmYaDjfiTyUIWFU3CyF hVVnP/ohC0bwrLjuWRY2swZDYbbyGatdE1/htYUG2Pxbf3kWi9G3KaeOxlTeb+6SNp0Y kgbA== X-Gm-Message-State: ABy/qLbvU7ZCaQFKcjYLB6+dWHzunGP2N0I6t/c9ApQ0h9tcT8HtRtvW 111SmKuGx5K+hRoGk38St1Xrow== X-Received: by 2002:a17:906:768d:b0:99b:cd0e:a805 with SMTP id o13-20020a170906768d00b0099bcd0ea805mr5645412ejm.37.1690808383337; Mon, 31 Jul 2023 05:59:43 -0700 (PDT) Received: from [192.168.1.20] ([178.197.222.183]) by smtp.gmail.com with ESMTPSA id um6-20020a170906cf8600b009930c61dc0esm6112815ejb.92.2023.07.31.05.59.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 Jul 2023 05:59:42 -0700 (PDT) Message-ID: Date: Mon, 31 Jul 2023 14:59:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.1 Subject: Re: [PATCH v3 2/2] i2c: Add GPIO-based hotplug gate Content-Language: en-US To: =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Cc: Svyatoslav Ryhel , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Wolfram Sang , linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230729160857.6332-1-clamor95@gmail.com> <20230729160857.6332-3-clamor95@gmail.com> <25858c22-ef92-2136-67ef-0d27364c1600@linaro.org> From: Krzysztof Kozlowski In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 31/07/2023 10:49, Michał Mirosław wrote: > On Mon, Jul 31, 2023 at 08:58:14AM +0200, Krzysztof Kozlowski wrote: >> On 30/07/2023 23:55, Michał Mirosław wrote: >>> On Sun, Jul 30, 2023 at 10:30:56PM +0200, Krzysztof Kozlowski wrote: >>>> On 29/07/2023 18:08, Svyatoslav Ryhel wrote: >>>>> From: Michał Mirosław >>>>> >>>>> Implement driver for hot-plugged I2C busses, where some devices on >>>>> a bus are hot-pluggable and their presence is indicated by GPIO line. >>> [...] >>>>> + priv->irq = platform_get_irq(pdev, 0); >>>>> + if (priv->irq < 0) >>>>> + return dev_err_probe(&pdev->dev, priv->irq, >>>>> + "failed to get IRQ %d\n", priv->irq); >>>>> + >>>>> + ret = devm_request_threaded_irq(&pdev->dev, priv->irq, NULL, >>>>> + i2c_hotplug_interrupt, >>>>> + IRQF_ONESHOT | IRQF_SHARED, >>>> >>>> Shared IRQ with devm is a recipe for disaster. Are you sure this is a >>>> shared one? You have a remove() function which also points that it is >>>> not safe. You can: >>>> 1. investigate to be sure it is 100% safe (please document why do you >>>> think it is safe) >>> >>> Could you elaborate on what is unsafe in using devm with shared >>> interrupts (as compared to non-shared or not devm-managed)? >>> >>> The remove function is indeed reversing the order of cleanup. The >>> shutdown path can be fixed by removing `remove()` and adding >>> `devm_add_action_or_reset(...deactivate)` before the IRQ is registered. >> Shared interrupt might be triggered easily by other device between >> remove() and irq release function (devm_free_irq() or whatever it is >> called). > > This is no different tham a non-shared interrupt that can be triggered > by the device being removed. Since devres will release the IRQ first, > before freeing the driver data, the interrupt hander will see consistent > driver-internal state. (The difference between remove() and devres > release phase is that for the latter sysfs files are already removed.) True, therefore non-devm interrupts are recommended also in such case. Maybe one of my solutions is actually not recommended. However if done right, driver with non-shared interrupts, is expected to disable interrupts in remove(), thus there is no risk. We have big discussions in the past about it, so feel free to dig through LKML to read more about. Anyway shared and devm is a clear no go. Best regards, Krzysztof