Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp313241rdb; Mon, 22 Jan 2024 05:13:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0G0YjFRJB3x0kAZdRQ0S77o8TdCdczdLSGqw58jbgoZY+0jB66SeFxIas3gDw6esNPbOF X-Received: by 2002:a17:907:8b90:b0:a2f:b9c0:4c0f with SMTP id tb16-20020a1709078b9000b00a2fb9c04c0fmr4371604ejc.4.1705929206993; Mon, 22 Jan 2024 05:13:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705929206; cv=pass; d=google.com; s=arc-20160816; b=rgQHwxfOXMziVN8H1uwjg9oCjlPr6lxk/PRbZH29+NaSRvlgxDDldJEuTVIs95koyq PMG2k/sZXrpRBQ1naW/85IQIq84FZ2hNGEdClf8wG309UWow5S0EEULKVWAo8EP3upKa wCIkOmdDI7/SP32HTpNqLNDooCiHBgbLagh7XHlOAFXj3k+ydA8cWYSpPeX7cfXT36zp e4J4rVF4cvfiq9N6wk+n/0pnvdaLsnA7Zt/XVldHaC81AtFc64CjoMVI/LMLt/UtZpQ1 HzMOW1cKOllhnXJkntj1WGzfH+g6mfZzBX+0NJ+YwWQSpoMzU1o5QkzxKH0us7YAMWQe k0ew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=BJTj6wcyWR9x7Ucgj0b0lcsFzl50SFu9dv/wKBaBgMA=; fh=zr4IdscT8lKc++5CfRUVgNN6JUdpADPILNyicVAaAkI=; b=CSj+uma84gXPuyp5BRqk9k4D3HBoETfH6JxnmjKNxdCAEUcGhOhFKoGZogrPkn1AhN gcJDb0BWiCIBDoFfwmeh7wFtMgr9/4UlP/+C4Whivv7YzpPD/r61pt3nFHG5TSrIgBol ra73L/mhwYRZblaY3+ASYE5F9MHiXa/3419uxBn6iIIdxp+FaZG/I7Gfdbt9fTUamqhw Q5y6NX1p+NoxmB+R8eDuez7fHR4TnCr4p2eKs2qBlR6IGj1DVQVaMrpNeSfqlF+DBbjP XvMEGAgPom1XgvusWuHC0oL2IoXu9c8FCdNYl42zhLSyc5lboz7ASsrSuPEytsWdb/gZ QjAQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VCdI5w7f; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-33074-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33074-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s16-20020a170906a19000b00a2a35fdd563si10702044ejy.28.2024.01.22.05.13.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 05:13:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33074-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VCdI5w7f; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-33074-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33074-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 057831F24E35 for ; Mon, 22 Jan 2024 13:11:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA8243C6AB; Mon, 22 Jan 2024 13:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="VCdI5w7f" Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D79E3C6BC for ; Mon, 22 Jan 2024 13:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705929104; cv=none; b=fZddp/3sD7dAC+lqf5HAbDXEBMkFhCzwW6E1ipR9R9Nevq+f82IEte5T+htAXolnI0h2Ees6caWaYP/10bW7YRCWi7aUnrzXcJCFfkCJClkQ+AHM1YFkGd9kKGvaP21nLcWfv2UaaiCWtRsUW41NN0gDhrmQHgz5M8coVZ4NdN8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705929104; c=relaxed/simple; bh=iFqukQALJCEAIiVjNq5raCIZC+Wze+COrL+a+qV52eY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UdbNgOnvfSDfYrmofL0hMDfK7Qq0yra6L3/KrMmW+o63I3ObDctLMZ5zwpU6fmxrKs4DCcNFnEDCE+2LiUsvSdi/tcJz9eOVKpPpDfxrtIqqbDfJmxOmHpQq8/MDHBNTE2EvKLJ+nPg/PMSNuXW2VEKPWuDQH5m2V8NhOiIAdn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=VCdI5w7f; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-40eb033c192so3301165e9.0 for ; Mon, 22 Jan 2024 05:11:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705929101; x=1706533901; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=BJTj6wcyWR9x7Ucgj0b0lcsFzl50SFu9dv/wKBaBgMA=; b=VCdI5w7fUY1u6Tj5b10GH4zay07JvivyjbNjXMoNGV5KLrwIC2uMgp2cWn0XEgc3cU ZoC6XpfJJC3Gy53b8FeUkShNvN9d1Ub3j6OIATzUxl1wwOdK6w0AU3cCa0E0koNjjWXK vODypDk34r0txnx90gvwe0RwaJA0EtxdLnnI9HU63HTQnkd1A6UTdusZue57WlS5pcLH OW1YFgNwHxwm/afiyERmu4Zpp/KI335IUeNMS4OKDNCKOqQobCz83OKImZV0CU1Darfc BztyUxivPRaDfVcDtXcbiIzwZMOYEMRCpCRORkH5yXjUY0aODD1NXxdBfKLhVbXaQSAa Oi9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705929101; x=1706533901; h=content-transfer-encoding:in-reply-to:autocrypt: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=BJTj6wcyWR9x7Ucgj0b0lcsFzl50SFu9dv/wKBaBgMA=; b=r0D+xS/zTILNxfs9qHu0SWGwujttxHr3jidw0EINpCjaO0uRlvx16BO/ttY3A4dtbS Te1UA7sVciCM2h0PSYSb6Scwg59qdu3X0nfVR+PZ4ZheLRBPIykRd1q/g/6b7KLK3z8w zbef8Cfl1Jkm/Il6ObsPGHVmN3J/rjyJLX9eIUPuQajQoYYiOyDT0AWF9Gyb46xgORKF WhqI612J3mNEFnS4czmkc8LnXuoy6BgLNP1RbRe+0D802Gi9GqqLiytrho8NklOkBws/ Hx5X1+Vjp1GdKzVvHk6AdK+RlO2wS1RzEKSEXNm1AhdhNUcKr4ekvzZqHNRl2YmoxxFv n/8g== X-Gm-Message-State: AOJu0YzSLvG9V+qqwGxmPE9NPK3cQXBXswfc/4CbewvjSwYoinXfRnJW 1Pxe6OBxsJ5JQmm49Dbvm4lVhr3a7r1VhSW1QJxFAvSf35GnPpKzvIm2jvISXew= X-Received: by 2002:a05:600c:4f55:b0:40e:a366:e718 with SMTP id m21-20020a05600c4f5500b0040ea366e718mr1867040wmq.42.1705929100682; Mon, 22 Jan 2024 05:11:40 -0800 (PST) Received: from [192.168.1.20] ([178.197.215.66]) by smtp.gmail.com with ESMTPSA id u13-20020a05600c19cd00b0040e451fd602sm42841958wmq.33.2024.01.22.05.11.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Jan 2024 05:11:40 -0800 (PST) Message-ID: <403b997a-ec01-4d41-a764-aea376f86362@linaro.org> Date: Mon, 22 Jan 2024 14:11:38 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/5] reset: Instantiate reset GPIO controller for shared reset-gpios Content-Language: en-US To: Philipp Zabel , Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peter Rosin , Jaroslav Kysela , Takashi Iwai , linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Bartosz Golaszewski , Chris Packham , Sean Anderson References: <20240112163608.528453-1-krzysztof.kozlowski@linaro.org> <20240112163608.528453-3-krzysztof.kozlowski@linaro.org> <568dc713f0c2fa29e5ba7b25c2d1d0e2be96fa95.camel@pengutronix.de> From: Krzysztof Kozlowski Autocrypt: addr=krzysztof.kozlowski@linaro.org; keydata= xsFNBFVDQq4BEAC6KeLOfFsAvFMBsrCrJ2bCalhPv5+KQF2PS2+iwZI8BpRZoV+Bd5kWvN79 cFgcqTTuNHjAvxtUG8pQgGTHAObYs6xeYJtjUH0ZX6ndJ33FJYf5V3yXqqjcZ30FgHzJCFUu JMp7PSyMPzpUXfU12yfcRYVEMQrmplNZssmYhiTeVicuOOypWugZKVLGNm0IweVCaZ/DJDIH gNbpvVwjcKYrx85m9cBVEBUGaQP6AT7qlVCkrf50v8bofSIyVa2xmubbAwwFA1oxoOusjPIE J3iadrwpFvsZjF5uHAKS+7wHLoW9hVzOnLbX6ajk5Hf8Pb1m+VH/E8bPBNNYKkfTtypTDUCj NYcd27tjnXfG+SDs/EXNUAIRefCyvaRG7oRYF3Ec+2RgQDRnmmjCjoQNbFrJvJkFHlPeHaeS BosGY+XWKydnmsfY7SSnjAzLUGAFhLd/XDVpb1Een2XucPpKvt9ORF+48gy12FA5GduRLhQU vK4tU7ojoem/G23PcowM1CwPurC8sAVsQb9KmwTGh7rVz3ks3w/zfGBy3+WmLg++C2Wct6nM Pd8/6CBVjEWqD06/RjI2AnjIq5fSEH/BIfXXfC68nMp9BZoy3So4ZsbOlBmtAPvMYX6U8VwD TNeBxJu5Ex0Izf1NV9CzC3nNaFUYOY8KfN01X5SExAoVTr09ewARAQABzTRLcnp5c3p0b2Yg S296bG93c2tpIDx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/oGRG KQ06ztUMRrj8eVtpImjsWCd0bDWRaaR4vqhCHvAG9iWXZu4qh3ipie2Y0oSJygcZT7H3UZxq fyYKiqEmRuqsvv6dcbblD8ZLkz1EVZL6djImH5zc5x8qpVxlA0A0i23v5QvN00m6G9NFF0Le D2GYIS41Kv4Isx2dEFh+/Q== In-Reply-To: <568dc713f0c2fa29e5ba7b25c2d1d0e2be96fa95.camel@pengutronix.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 15/01/2024 17:55, Philipp Zabel wrote: > On Fr, 2024-01-12 at 17:36 +0100, Krzysztof Kozlowski wrote: >> >> +static bool __reset_gpios_args_match(const struct of_phandle_args *a1, >> + const struct of_phandle_args *a2) >> +{ >> + unsigned int i; >> + >> + if (!a2) >> + return false; >> + >> + if (a1->args_count != a2->args_count) >> + return false; >> + >> + for (i = 0; i < a1->args_count; i++) >> + if (a1->args[i] != a2->args[i]) >> + return false; >> + >> + return true; >> +} > > How about making this > > return a2 && > a1->np == a2->np && > a1->args_count == a2->args_count && > !memcmp(a1->args, a2->args, sizeof(a1->args[0]) * a1->args_count); > > ? > > There's similar code in include/linux/cpufreq.h, maybe this could later > be lifted into a common of_phandle_args_equal(). I'll make a helper because such long return is also not the fastest to parse by brain. > >> + >> +static int __reset_add_reset_gpio_lookup(int id, struct device_node *np, >> + unsigned int gpio, >> + unsigned int of_flags) >> +{ >> + struct gpiod_lookup_table *lookup __free(kfree) = NULL; >> + struct gpio_device *gdev __free(gpio_device_put) = NULL; >> + char *label __free(kfree) = NULL; >> + unsigned int lookup_flags; >> + >> + /* >> + * Later we map GPIO flags between OF and Linux, however not all >> + * constants from include/dt-bindings/gpio/gpio.h and >> + * include/linux/gpio/machine.h match each other. >> + */ >> + if (of_flags > GPIO_ACTIVE_LOW) { >> + pr_err("reset-gpio code does not support GPIO flags %u for GPIO %u\n", >> + of_flags, gpio); >> + return -EINVAL; >> + } >> + >> + gdev = gpio_device_find_by_fwnode(of_fwnode_handle(np)); >> + if (!gdev) >> + return -EPROBE_DEFER; >> + >> + label = kstrdup(gpio_device_get_label(gdev), GFP_KERNEL); >> + if (!label) >> + return -EINVAL; > > The kstrdup() failure looks like it should be -ENOMEM to me. > I'd check the gpio_device_get_label(gdev) return value separately. OK, makes sense. One more local variable will be needed for that. > > Is this going to be in v6.8-rc1, or does using gpio_device_get_label() > introduce a dependency? We were already in the merge window, so no problem here. gpio_device_get_label() is in v6.8-rc1. > >> + >> + /* Size: one lookup entry plus sentinel */ >> + lookup = kzalloc(struct_size(lookup, table, 2), GFP_KERNEL); >> + if (!lookup) >> + return -ENOMEM; >> + >> + lookup->dev_id = kasprintf(GFP_KERNEL, "reset-gpio.%d", id); >> + if (!lookup->dev_id) >> + return -ENOMEM; >> + >> + lookup_flags = GPIO_PERSISTENT; >> + lookup_flags |= of_flags & GPIO_ACTIVE_LOW; >> + lookup->table[0] = GPIO_LOOKUP(no_free_ptr(label), gpio, "reset", >> + lookup_flags); >> + >> + gpiod_add_lookup_table(no_free_ptr(lookup)); >> + >> + return 0; >> +} >> + >> +/* >> + * @reset_args: phandle to the GPIO provider with all the args like GPIO number > > s/reset_// ack > >> + */ >> +static int __reset_add_reset_gpio_device(const struct of_phandle_args *args) >> +{ >> + struct reset_gpio_lookup *rgpio_dev; >> + struct platform_device *pdev; >> + int id, ret; >> + >> + /* >> + * Registering reset-gpio device might cause immediate >> + * bind, resulting in its probe() registering new reset controller thus >> + * taking reset_list_mutex lock via reset_controller_register(). >> + */ >> + lockdep_assert_not_held(&reset_list_mutex); >> + >> + mutex_lock(&reset_gpio_lookup_mutex); >> + >> + list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) { >> + if (args->np == rgpio_dev->of_args.np) { >> + if (__reset_gpios_args_match(args, &rgpio_dev->of_args)) >> + goto out; /* Already on the list, done */ >> + } >> + } >> + >> + id = ida_alloc(&reset_gpio_ida, GFP_KERNEL); >> + if (id < 0) { >> + ret = id; >> + goto err_unlock; >> + } >> + >> + /* >> + * Not freed in normal path, persisent subsystem data (which is assumed >> + * also in the reset-gpio driver). >> + */ >> + rgpio_dev = kzalloc(sizeof(*rgpio_dev), GFP_KERNEL); >> + if (!rgpio_dev) { >> + ret = -ENOMEM; >> + goto err_ida_free; >> + } >> + >> + ret = __reset_add_reset_gpio_lookup(id, args->np, args->args[0], >> + args->args[1]); >> + if (ret < 0) >> + goto err_kfree; >> + >> + rgpio_dev->of_args = *args; >> + /* >> + * We keep the device_node reference, but of_args.np is put at the end >> + * of __of_reset_control_get(), so get it one more time. >> + * Hold reference as long as rgpio_dev memory is valid. >> + */ >> + of_node_get(rgpio_dev->of_args.np); >> + pdev = platform_device_register_data(NULL, "reset-gpio", id, >> + &rgpio_dev->of_args, >> + sizeof(rgpio_dev->of_args)); >> + ret = PTR_ERR_OR_ZERO(pdev); >> + if (ret) >> + goto err_put; >> + >> + list_add(&rgpio_dev->list, &reset_gpio_lookup_list); >> + >> +out: >> + mutex_unlock(&reset_gpio_lookup_mutex); >> + >> + return 0; >> + >> +err_put: >> + of_node_put(rgpio_dev->of_args.np); >> +err_kfree: >> + kfree(rgpio_dev); >> +err_ida_free: >> + ida_free(&reset_gpio_ida, id); >> +err_unlock: >> + mutex_unlock(&reset_gpio_lookup_mutex); >> + >> + return ret; >> +} >> + >> +static struct reset_controller_dev *__reset_find_rcdev(const struct of_phandle_args *args, >> + bool gpio_fallback) >> +{ >> + struct reset_controller_dev *r, *rcdev; > > Now that this is moved into a function, there's no need for the r, > rcdev split anymore. Just return a match when found, and NULL at the > end: > > struct reset_controller_dev *rcdev; Indeed, thanks. > >> + >> + lockdep_assert_held(&reset_list_mutex); >> + >> + rcdev = NULL; >> + list_for_each_entry(r, &reset_controller_list, list) { > > list_for_each_entry(rcdev, &reset_controller_list, list) { > >> + if (args->np == r->of_node) { >> + if (gpio_fallback) { >> + if (__reset_gpios_args_match(args, r->of_args)) { >> + rcdev = r; >> + break; > > return rcdev; > >> + } >> + } else { >> + rcdev = r; >> + break; >> + } >> + } > > With the np check moved into __reset_gpios_args_match() above, the > whole loop could be turned into: > > if (gpio_fallback) { > if (__reset_gpios_args_match(args, rcdev->of_args)) > return rcdev; > } else { > if (args->np == rcdev->of_node) > return rcdev; > } > > Explicitly checking against rcdev->of_args->np instead of rcdev- >> of_node in gpio_fallback mode could avoid false positives in case > anybody ever creates a combined GPIO and reset controller device and > then uses its GPIOs to drive a shared reset line.. ack > >> + } >> + >> + return rcdev; > > return NULL; ack > >> +} >> >> struct reset_control * >> __of_reset_control_get(struct device_node *node, const char *id, int index, >> bool shared, bool optional, bool acquired) >> { >> + struct of_phandle_args args = {0}; > > Is this still needed? I will double check. > >> + bool gpio_fallback = false; >> struct reset_control *rstc; >> - struct reset_controller_dev *r, *rcdev; >> - struct of_phandle_args args; >> + struct reset_controller_dev *rcdev; >> int rstc_id; >> int ret; >> >> @@ -839,39 +1028,49 @@ __of_reset_control_get(struct device_node *node, const char *id, int index, >> index, &args); >> if (ret == -EINVAL) >> return ERR_PTR(ret); >> - if (ret) >> - return optional ? NULL : ERR_PTR(ret); >> + if (ret) { >> + /* >> + * There can be only one reset-gpio for regular devices, so >> + * don't bother with GPIO index. >> + */ >> + ret = of_parse_phandle_with_args(node, "reset-gpios", "#gpio-cells", >> + 0, &args); >> + if (ret) >> + return optional ? NULL : ERR_PTR(ret); >> >> - mutex_lock(&reset_list_mutex); >> - rcdev = NULL; >> - list_for_each_entry(r, &reset_controller_list, list) { >> - if (args.np == r->of_node) { >> - rcdev = r; >> - break; >> + gpio_fallback = true; >> + >> + ret = __reset_add_reset_gpio_device(&args); >> + if (ret) { >> + rstc = ERR_PTR(ret); >> + goto out_put; >> } >> } >> >> + mutex_lock(&reset_list_mutex); >> + rcdev = __reset_find_rcdev(&args, gpio_fallback); >> if (!rcdev) { >> rstc = ERR_PTR(-EPROBE_DEFER); >> - goto out; >> + goto out_unlock; >> } >> >> if (WARN_ON(args.args_count != rcdev->of_reset_n_cells)) { > > Nice. I like that the __of_reset_control_get() changes are much less > invasive now. > >> rstc = ERR_PTR(-EINVAL); >> - goto out; >> + goto out_unlock; >> } >> >> rstc_id = rcdev->of_xlate(rcdev, &args); >> if (rstc_id < 0) { >> rstc = ERR_PTR(rstc_id); >> - goto out; >> + goto out_unlock; >> } >> >> /* reset_list_mutex also protects the rcdev's reset_control list */ >> rstc = __reset_control_get_internal(rcdev, rstc_id, shared, acquired); >> >> -out: >> +out_unlock: >> mutex_unlock(&reset_list_mutex); >> +out_put: >> of_node_put(args.np); >> >> return rstc; >> diff --git a/include/linux/reset-controller.h b/include/linux/reset-controller.h >> index 0fa4f60e1186..e064473215de 100644 >> --- a/include/linux/reset-controller.h >> +++ b/include/linux/reset-controller.h >> @@ -61,6 +61,9 @@ struct reset_control_lookup { >> * @dev: corresponding driver model device struct >> * @of_node: corresponding device tree node as phandle target >> * @of_reset_n_cells: number of cells in reset line specifiers >> + * TODO: of_args have of_node, so we have here duplication > > Any plans what to do about this? With the above changes we could > mandate that either of_node or of_args should be set, never both. Yes, makes sense. We could also drop of_node, but the code won't be more readable. Best regards, Krzysztof