Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp784032rdg; Fri, 13 Oct 2023 00:23:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHt7pLuAko0cbQnCLfFO+tdkvGmCtc0Lx++eQfRFRQkPg4e44jFvqN7K7HWAW2PUvMaMy8C X-Received: by 2002:a05:6358:885:b0:143:91a2:8e0a with SMTP id m5-20020a056358088500b0014391a28e0amr28784163rwj.4.1697181838311; Fri, 13 Oct 2023 00:23:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697181838; cv=none; d=google.com; s=arc-20160816; b=SulVvmS6sEgzGhp/ub39qb1ZjQ70a0deThSaaezPwvlWDLdNdWIteULevgMRW4tjy2 T2KDCcsKPfxTeMYah45Yq+KGCTe1OBQ6zyir2kO5FyxzHpViCWcqWuhWTQyuNo17O/QM rbNvuryrk2v9pjzIdt0ykiLC1bcECz9TS0diq0dBVOSLGxHJHqV3JZ6rsaVbRsllbNd8 UdDEllyqeL04tlRz6tX1pSNXbvt7cgP/kqi2uMSZE7CII9/f3Jfd4MXZP+x1fMdRUHU+ pboZ3dfc3sKTp4Tkebym4+3J6TJReL39isAvvhLHNUQ/6TWrqex1iVPbkuMdMMu4phWC 8A+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Gb3gYagB6dDOUEqTcgUJ+Jm7aEOybfjvWpE6CZqOl1I=; fh=ykizkEEU4lK6MCLJPYu7cYaYUE6OLtFvF5XwX3qOmQs=; b=IJ7G+1pGfc6ytJHUL0r1tdYzy4Fbx3Z7kQHoW9nJR7KyRpk1851e3d/wwe3zONNjQp qrJpuh/LgQEEDGv28OlCRaoxeD80PgRjXrhf6HpkQezU2BFF7m6F2fYzEQ69zVOGy3Y/ BZH2g59oYUms8sRfxxoDjBFN98DIJtzxF1Zr++jsEMXMiFD5C4sN9pXv8mFQUztx+qYb n+xZRSVlv24d3fPHfm0upyLtEM1cZ7OR7ZRs7b0OSaEJKeKbILNpK84ekgMO0z3myCMm T2Y77kL+yfZKf3bsm3NsIsVNZ1EyiJTULFzZBUnIHzBuuzpLp+Qn2Ps/67FpXiM86p2w HwKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=bwuMD1bA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id dc4-20020a056a0035c400b0068a6f6d9f85si14291585pfb.140.2023.10.13.00.23.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:23:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=bwuMD1bA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DCAD880254C2; Fri, 13 Oct 2023 00:23:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229751AbjJMHXt (ORCPT + 99 others); Fri, 13 Oct 2023 03:23:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbjJMHXs (ORCPT ); Fri, 13 Oct 2023 03:23:48 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19035BC for ; Fri, 13 Oct 2023 00:23:47 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4066241289bso18843175e9.0 for ; Fri, 13 Oct 2023 00:23:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1697181825; x=1697786625; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Gb3gYagB6dDOUEqTcgUJ+Jm7aEOybfjvWpE6CZqOl1I=; b=bwuMD1bAxLcmK+He1bJrevM0UBZt7CQ/8n7HyEI9S+H9+Gu9kWWcQSo8Z+X5jegCMI pBKe2zjA1X8R4EW0zABzNK6hLgBFwmVSHk9VzRJHSdcfC8MJo4fhDRny1r4k3SHeyl+F px5QDDLubNQ/sqfQeGcxnqtg/KSMS2ud90DTztGMbKdT1WLPGQiLLXJmMOvdTnq02El4 7hyWbC5dSuru3LN7FNTshcsTp1/YUz0NNOTZSuZa+n6zB4OaBzQpKqxXqrXO1Dr0QEF5 BahptbaKltsHcIjDWI8vb6k2vDqW9/HVpEG5x4GXuzLXsrvKsobsCYxyFCigwazIImXl wuUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697181825; x=1697786625; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Gb3gYagB6dDOUEqTcgUJ+Jm7aEOybfjvWpE6CZqOl1I=; b=DpnQet1qBsdJ8RuQJh+0YR+sFEm79hGYP23xMRw4zmWj2JOxOCUWUV+aRYFnOkekTS EmWoLbWvOSjd0n4bjfyE5paVNTZWVRVGPv5zk8/wkOwIhIwsa5nNE6PNWoHxtYLulBEA dzuHu/VYMIN7rwv/EuUpJaxURjG5RhSFM90SiPJnAFcD/pQQH7FZdQ7OtQBlw0rku/Cp SA5oITl4oaZuh577BWuW1qx8LKs26oJ8K3VFkckQ8j253OL1wDXQ5wpGSRfBMkR2Y+Bw h0JbxT1pWCmGow0QZjyDXpCm1/+L7pCxWDgOpQzjKmBCWLfua3ZHkKnESHwAd7ZfHRfg ignw== X-Gm-Message-State: AOJu0YzhXBWPIGha77K8+IfzwoH9qSCHy48/iFcmnseAiDu2I6KHhyym RSFp3OItc1viDGNe4BZT5zJUZ+lsebhcrzsNk6Q= X-Received: by 2002:a05:600c:21ce:b0:407:68a3:6b5d with SMTP id x14-20020a05600c21ce00b0040768a36b5dmr3284206wmj.23.1697181825417; Fri, 13 Oct 2023 00:23:45 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4209:13a:988d:80be]) by smtp.gmail.com with ESMTPSA id y4-20020a1c4b04000000b004075d5664basm1775581wma.8.2023.10.13.00.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:23:45 -0700 (PDT) From: Bartosz Golaszewski To: Dipen Patel , Thierry Reding , Jonathan Hunter , Linus Walleij , Andy Shevchenko Cc: timestamp@lists.linux.dev, linux-kernel@vger.kernel.org, Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v2] hte: tegra194: don't access struct gpio_chip Date: Fri, 13 Oct 2023 09:23:40 +0200 Message-Id: <20231013072340.16411-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 13 Oct 2023 00:23:56 -0700 (PDT) From: Bartosz Golaszewski Using struct gpio_chip is not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted struct gpio_device and its dedicated accessors. Signed-off-by: Bartosz Golaszewski Tested-by: Dipen Patel Reviewed-by: Linus Walleij [andy: used gpio_device_find_by_fwnode()] Reviewed-by: Dipen Patel Link: https://lore.kernel.org/r/20231010151709.4104747-3-andriy.shevchenko@linux.intel.com Signed-off-by: Andy Shevchenko --- Dipen, Can you retest this patch now rebased on top of current GPIO for-next? v1 -> v2: - rebase on top of current gpio/for-next drivers/hte/hte-tegra194.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/hte/hte-tegra194.c b/drivers/hte/hte-tegra194.c index 6fe6897047ac..341a134cb7d0 100644 --- a/drivers/hte/hte-tegra194.c +++ b/drivers/hte/hte-tegra194.c @@ -132,7 +132,7 @@ struct tegra_hte_soc { const struct tegra_hte_data *prov_data; struct tegra_hte_line_data *line_data; struct hte_chip *chip; - struct gpio_chip *c; + struct gpio_device *gdev; void __iomem *regs; }; @@ -418,7 +418,7 @@ static int tegra_hte_line_xlate(struct hte_chip *gc, * HTE/GTE namespace. */ if (gs->prov_data->type == HTE_TEGRA_TYPE_GPIO && !args) { - line_id = desc->attr.line_id - gs->c->base; + line_id = desc->attr.line_id - gpio_device_get_base(gs->gdev); map = gs->prov_data->map; map_sz = gs->prov_data->map_sz; } else if (gs->prov_data->type == HTE_TEGRA_TYPE_GPIO && args) { @@ -645,7 +645,7 @@ static bool tegra_hte_match_from_linedata(const struct hte_chip *chip, if (!hte_dev || (hte_dev->prov_data->type != HTE_TEGRA_TYPE_GPIO)) return false; - return hte_dev->c == gpiod_to_chip(hdesc->attr.line_data); + return hte_dev->gdev == gpiod_to_gpio_device(hdesc->attr.line_data); } static const struct of_device_id tegra_hte_of_match[] = { @@ -673,14 +673,11 @@ static void tegra_gte_disable(void *data) tegra_hte_writel(gs, HTE_TECTRL, 0); } -static int tegra_get_gpiochip_from_name(struct gpio_chip *chip, void *data) +static void tegra_hte_put_gpio_device(void *data) { - return !strcmp(chip->label, data); -} + struct gpio_device *gdev = data; -static int tegra_gpiochip_match(struct gpio_chip *chip, void *data) -{ - return chip->fwnode == of_node_to_fwnode(data); + gpio_device_put(gdev); } static int tegra_hte_probe(struct platform_device *pdev) @@ -760,8 +757,8 @@ static int tegra_hte_probe(struct platform_device *pdev) if (of_device_is_compatible(dev->of_node, "nvidia,tegra194-gte-aon")) { - hte_dev->c = gpiochip_find("tegra194-gpio-aon", - tegra_get_gpiochip_from_name); + hte_dev->gdev = + gpio_device_find_by_label("tegra194-gpio-aon"); } else { gpio_ctrl = of_parse_phandle(dev->of_node, "nvidia,gpio-controller", @@ -772,14 +769,19 @@ static int tegra_hte_probe(struct platform_device *pdev) return -ENODEV; } - hte_dev->c = gpiochip_find(gpio_ctrl, - tegra_gpiochip_match); + hte_dev->gdev = + gpio_device_find_by_fwnode(of_fwnode_handle(gpio_ctrl)); of_node_put(gpio_ctrl); } - if (!hte_dev->c) + if (!hte_dev->gdev) return dev_err_probe(dev, -EPROBE_DEFER, "wait for gpio controller\n"); + + ret = devm_add_action_or_reset(dev, tegra_hte_put_gpio_device, + hte_dev->gdev); + if (ret) + return ret; } hte_dev->chip = gc; -- 2.39.2