Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp3732356rwb; Sun, 30 Jul 2023 15:00:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlE2KYKWUd+Nje7sg2UtxiZ6N5/07lkE1ETTbom7GT4hb3H8rTOr1ywrigdiIHF43Ut2pMXT X-Received: by 2002:a05:6402:3552:b0:522:405f:a7 with SMTP id f18-20020a056402355200b00522405f00a7mr12306251edd.16.1690754431480; Sun, 30 Jul 2023 15:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690754431; cv=none; d=google.com; s=arc-20160816; b=I5dRoFrtgzhawsYDiiNYmXSbrFbGb0h0PwP65oX45ywniqMHZHanlAU+0yqwNRUnUN QgXnBbMIiKf5hAgSiBYl5ebDV0Ru1e5PQnx1OTwUQ1wjLrS+EgSyCjBa+qHev/JqTZjk SvkoOsOdBfBsEAVWwZ4IcCiSVUJfUztqh2GsQX8biKurbsVAbkTYmyGNhxBe4ONyJs34 LSSvAvF9xQuUeDDoUE5Oj12kkV+UMl4lZCfI6RAenPpIJOr1klsnhAawDjfM984qhp1J y+BSzkdHpJMbSG6yVpITwHfRGKHGCatrgWF7gZUY5JXcXfZSmWXbv3uUDjK35wB1dQAG rfGw== 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=vxg8TeRb0NZN4rPS9q09YPBYQiS+mNKDuiZUWy7sPoE=; fh=tuLM0WZXhk/b+hqCY/X/HTDOdgqrqqZojhg/W32RMkc=; b=OywCwMLnuHSkF88KAlvCWcb93uv4Zh9pWgvVSBUtg5cORPyQrfeqLCkpe5nHBKQGcP B/IdL2Cxg+qXplNh03OW7KdODBlTkemiKFZMnfJiXfRR5IyUhHU/wqL4aX9rlcil8y2M qjNh9PzntJRIMgmSJV4AvhaGXpVNh36kVvTz6weMlwXB24YbFjeU9gt6T2XnD4KrHz9g 7MFJJonoosJ/U3mMRF7GHEM2zF0bMf2FOCG5T7fVSFbiRIQOzyGJFEUP4YX7vKAejGNK wClaAfuhl176MDvp8m/Ph5RfOHBfGfGQRXsKpWp+em/gxNruQWjf0Ao/FLWkCv24qwHp QA5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T2n6ZC3L; 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 d10-20020aa7d5ca000000b00522b112625asi2538373eds.360.2023.07.30.15.00.03; Sun, 30 Jul 2023 15:00:31 -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=T2n6ZC3L; 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 S229505AbjG3UbE (ORCPT + 99 others); Sun, 30 Jul 2023 16:31:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbjG3UbC (ORCPT ); Sun, 30 Jul 2023 16:31:02 -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 C254C113 for ; Sun, 30 Jul 2023 13:31:00 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-99c10ba30afso106984166b.1 for ; Sun, 30 Jul 2023 13:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690749059; x=1691353859; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=vxg8TeRb0NZN4rPS9q09YPBYQiS+mNKDuiZUWy7sPoE=; b=T2n6ZC3LdIPpNjPMhN0clIMSRupAJ5wmAIrIV2AoJfro+kU5iA8/4yn42jO6rr69KY wlFKXo9FYxNLBpVmMuMD7xjD7OfDUHbdkDV5H4bL5F1gwwgYCoBVQziK2Ov72H+8AYXD dAs3n55aJS/5MJTM41Sk2zeIycwOvxCY392vlX/oUddRdV4BebFpNM/2yxnMzjPoILmv kL6nr9rbvkKvpw2Z+POeAAWSI5wmttSM6ttgdwlNXQZ1xhi2CPIzvSdVAGv4oFnZQPsb oNKKsCSf/9bgaDzt1UY1bsmaolIp+qu61sqcEKIHVawKKhkzmGr2oTGz8jxq1KQq1KDT aMzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690749059; x=1691353859; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vxg8TeRb0NZN4rPS9q09YPBYQiS+mNKDuiZUWy7sPoE=; b=hGJbXF/TwABzweiGCOGJSfpaFVJzA5s4rsF8pWUkI/jMxk+eLfXJQ+nLMZJpe6o28S PHH8l+e9gG14U1AUlu5Lxjm8VkzKFnKDCjfzNVwE8OOkSL6bFWkjzv2W+qxaaxuTjzu3 oLu6MrK/zWJvdQbLA8Fp+rYK38qZ3jZjQjwh7k2yCEKEZ37DAH3qcNYarsNzkDkGr5VZ xMNzT1jGGAiVdOMBt2PQfaHNZqLyiUiv05Ap3Et2gbxs/iTkJgz0oU3uv6qumryEK158 o1HPQCyrOQOH2H6HvcASeHe9C+TAkyU11D4+TL5vpnrayJN45rwz//IxdHFSS91Q2upS fcTg== X-Gm-Message-State: ABy/qLaY7r/AM8ye4EAsHCn752zNxmb9pjix7fmIdk6pPO5lqjmv5woX b/1qb0UErAiR73Hh168Lz6P8aQ== X-Received: by 2002:a17:906:53d0:b0:99b:4d3d:c9b7 with SMTP id p16-20020a17090653d000b0099b4d3dc9b7mr6068918ejo.31.1690749059260; Sun, 30 Jul 2023 13:30:59 -0700 (PDT) Received: from [192.168.1.20] ([178.197.222.183]) by smtp.gmail.com with ESMTPSA id n22-20020a170906841600b009934707378fsm5072399ejx.87.2023.07.30.13.30.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 30 Jul 2023 13:30:58 -0700 (PDT) Message-ID: <25858c22-ef92-2136-67ef-0d27364c1600@linaro.org> Date: Sun, 30 Jul 2023 22:30:56 +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 To: Svyatoslav Ryhel , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Wolfram Sang , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Cc: 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> Content-Language: en-US From: Krzysztof Kozlowski In-Reply-To: <20230729160857.6332-3-clamor95@gmail.com> 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_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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. > > This feature is mainly used by the ASUS Transformers family. The > Transformers have a connector that's used for USB, charging or for > attaching a dock-keyboard (which also has a battery and a touchpad). > This connector probably (can't be verified since no datasheets or > special equipment is available) has an I2C bus lines and a "detect" > line (pulled low on the dock side) among the pins. I guess there > is either no additional chip or a transparent bridge/buffer chip, > but nothing that could be controlled by software. For DT this setup > could be modelled like an I2C gate or 2-port mux with enable joining > two I2C buses (one "closer" to the CPU as a parent). > > Co-developed-by: Ion Agorria > Signed-off-by: Ion Agorria > Signed-off-by: Michał Mirosław > Signed-off-by: Svyatoslav Ryhel ... > + ret = devm_add_action_or_reset(&pdev->dev, devm_i2c_put_adapter, > + parent); > + if (ret) > + return ret; > + > + priv->gpio = devm_gpiod_get(&pdev->dev, "detect", GPIOD_IN); > + if (IS_ERR(priv->gpio)) > + return dev_err_probe(&pdev->dev, PTR_ERR(priv->gpio), > + "failed to get detect GPIO\n"); > + > + is_i2c = parent->algo->master_xfer; > + is_smbus = parent->algo->smbus_xfer; > + > + snprintf(priv->adap.name, sizeof(priv->adap.name), > + "i2c-hotplug (master i2c-%d)", i2c_adapter_id(parent)); > + priv->adap.owner = THIS_MODULE; > + priv->adap.algo = i2c_hotplug_algo[is_i2c][is_smbus]; > + priv->adap.algo_data = NULL; > + priv->adap.lock_ops = &i2c_hotplug_lock_ops; > + priv->adap.class = parent->class; > + priv->adap.retries = parent->retries; > + priv->adap.timeout = parent->timeout; > + priv->adap.quirks = parent->quirks; > + if (parent->bus_recovery_info) > + priv->adap.bus_recovery_info = &i2c_hotplug_recovery_info; > + > + if (!priv->adap.algo) > + return -EINVAL; > + > + 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) 2. drop devm 3. drop shared flag. Best regards, Krzysztof