Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp625403rdb; Mon, 15 Jan 2024 08:13:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IErB9H0EK38mbiFSqlv7GitmrF8jQS7VtJmCCkKb81vPQkUP9LyQYRLES0RqFTkn3Hj8SUt X-Received: by 2002:a2e:a4a4:0:b0:2cc:7174:48fb with SMTP id g4-20020a2ea4a4000000b002cc717448fbmr2575797ljm.40.1705335218987; Mon, 15 Jan 2024 08:13:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705335218; cv=none; d=google.com; s=arc-20160816; b=pROYh9GTJ9vVpztfATm0+CXDMDZqpDJIGDmJKF8HENYAqpsvbwbVCPKnnIH/gA0m2j F9xgr4MoBb8+tjNW92DUo0xaInavzbj6zle+ttHrlu0JrWtaZONuq3BL0hwVFoKZifHn JzlXtZidyNkUE/fj9MHrEy9v7PYapFIGAGj6lcvzVu6RgaDF+9xLjrCvzoGPCEJ2a2zC bx/61ZMOYObilXb1+XV0/qRhgIVz+9BGIfjTJ9g1qNgkM8IbA11+LiEdO4LG4vC8Bzf8 Xv9zpV6/JdvMsyLLB36SjKoeg3Tc0xlB7ZtfBwsbY/Bd/9XdZhS2yi5+yJ/KOh2Vs4Hq u+XQ== ARC-Message-Signature: i=1; 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=nVYrgvSB/hdaXbdnvDLjcsaxrQx0tnZ31np8n8fE/8Q=; fh=xesrUxzsyqs7Q4oJgJRFtqCQ2Jqv6arjP22inJFMHJU=; b=M8i2PFCbsDrcfntBEzJ0RVGCWH/zt/uFYpKEqN3fsm7/8q/+qX4/NGJydvkUKctfak b0so+bEPTkNOWsoGWoyaWt/F8pUC7O1l70p5YI7qrQpZGp4brUHR1/xaJana4oW60sXM HDgX0hxsCZgWNkF1exZYs3Z293IEuBg4Yhr/u7uI5c9k3RNN0nNCBXsKgsTWCg5Gj819 muUqpz0WMrtJIpbmO/3fxEFTaAvXYA2Pu2u81rGyTz372nWaRVtcNsR950V8aIw60sUk nEB8XPvzALIeFDEdbyOY8pe8lQfCA65rRSgOy/eJrFNl/W08AGltvGztP/I/3sWvyh4/ Gkvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OHS6mVyz; spf=pass (google.com: domain of linux-kernel+bounces-26230-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26230-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id en21-20020a056402529500b00558251ade8asi4151585edb.117.2024.01.15.08.13.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 08:13:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26230-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OHS6mVyz; spf=pass (google.com: domain of linux-kernel+bounces-26230-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26230-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 8C1E51F241A0 for ; Mon, 15 Jan 2024 16:13:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B318D17BB2; Mon, 15 Jan 2024 16:13:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OHS6mVyz" Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 28A6417BA0 for ; Mon, 15 Jan 2024 16:13:26 +0000 (UTC) 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-ej1-f50.google.com with SMTP id a640c23a62f3a-a2dc7827a97so133117166b.2 for ; Mon, 15 Jan 2024 08:13:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705335204; x=1705940004; 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=nVYrgvSB/hdaXbdnvDLjcsaxrQx0tnZ31np8n8fE/8Q=; b=OHS6mVyz0+8/YcMybmKM41RZR0pXyRq5RkLOCkJgnvl971F6q2zF5+hLS8gKdO5gfV Fv+iVdKYe7jnsRb6jjs9/0OkuCM8aStVUvEE1BkXnq8btG/hq84CjZqOtIPYtkZOm5VY MN16wONBjrBy6uieqPTovkYpgOWFB4+/LtKvPECg1ErImnKKCCvGLX1uldj6x8hsmvOF kDoFIXZGgRANe6DhYImwU7a3fTsfeucqr65apE913Xv7z2heTl1S1fc1myJwO+IdJmpo t6M0NLACaFBZVi6HpH0rgH6vnzlbGZICO8ds3UykWtCXqnoOztGoZF4RyfjVStf5/X4H s8iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705335204; x=1705940004; 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=nVYrgvSB/hdaXbdnvDLjcsaxrQx0tnZ31np8n8fE/8Q=; b=SK8scNaPsYYkrzRSaVLykqe+wh5jtueCADRxpHQN4UypEJ8Iw2RqNJBVqytQ54+N5x QxINGtmYlUWLa0us/JpBbFmorqxZ/whnTdyCQX6RK/ngbvBSBZsOrY5VbpY+7yDGHMUG lGD0PAlN3lAfZpnqbBGc2kMcjJqYNu5sNaN1MI3e1yBgSFn7Mg5I+irbL4xWeBFw0jag +Gx1fI8Kb1oivASfWT6bsa+c0rK9x0VlH+6dY9Bg0CCOui/K2+j8TZ27Z70YHuEQUwLv /K//b/EXwnAEFFUBnOxQogMHr8kBPF8l4b8Zqz/ztNNDJabTBDL+/7Kb/JyciTd29Mzu vqtQ== X-Gm-Message-State: AOJu0YzscaiyIB5O5csOh+Tz9V5Zl9xav0TsaDrDc1NLP+nymq22fSQ4 gocO0VulmWtMArQVM9J9lqeJweS4QFqVuA== X-Received: by 2002:a17:906:37cc:b0:a2b:2615:25d3 with SMTP id o12-20020a17090637cc00b00a2b261525d3mr2642917ejc.136.1705335204374; Mon, 15 Jan 2024 08:13:24 -0800 (PST) Received: from [192.168.1.20] ([178.197.215.66]) by smtp.gmail.com with ESMTPSA id bm19-20020a170906c05300b00a2362c5e3dbsm5417864ejb.151.2024.01.15.08.13.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Jan 2024 08:13:23 -0800 (PST) Message-ID: <7f311659-9f49-44dc-ad40-977d34066d98@linaro.org> Date: Mon, 15 Jan 2024 17:13:21 +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: Bartosz Golaszewski Cc: Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peter Rosin , Philipp Zabel , 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, Chris Packham , Sean Anderson References: <20240112163608.528453-1-krzysztof.kozlowski@linaro.org> <20240112163608.528453-3-krzysztof.kozlowski@linaro.org> 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/RjI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c+rJggwMQcJL9F+oDm3wX47nr6jIsEB5ZftdybIzpMZ5V9v45lUwmdnMrSzZVgC4jRGXzsU EViBQt2CopXtHtYfPAO5nAkIvKSNp3jmGxZw4aTc5xoAZBLo0OV+Ezo71pg3AYvq0a3/oGRG KQ06ztUMRrj8eVtpImjsWCd0bDWRaaR4vqhCHvAG9iWXZu4qh3ipie2Y0oSJygcZT7H3UZxq fyYKiqEmRuqsvv6dcbblD8ZLkz1EVZL6djImH5zc5x8qpVxlA0A0i23v5QvN00m6G9NFF0Le D2GYIS41Kv4Isx2dEFh+/Q== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 15/01/2024 17:06, Bartosz Golaszewski wrote: >> + >> +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; > > I got yelled at by Linus Torvalds personally for doing it like this. I > know this is a common pattern in code using GLib but Linus wants auto > variables to be initialized where they're declared... Declaration is here. Initialization is here. Therefore this is initialized where it is declared. What's more it is initialized to a valid value, because __free() accepts NULLs. > >> + 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)); > > ... so this should become: > > struct gpio_device *gdev __free(gpio_device_put) = gpio_device_find(...) > > and same for the rest. > > Don't get me wrong, I love cleanup.h but there's a (unofficial for > now) coding style. So you just want to declare it not in top-part of the function but just before first use? > >> + if (!gdev) >> + return -EPROBE_DEFER; >> + >> + label = kstrdup(gpio_device_get_label(gdev), GFP_KERNEL); >> + if (!label) >> + return -EINVAL; >> + >> + /* 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)); > > You told me that this doesn't need to be removed or ever freed but a > comment on that would be in order. Sure, code further comments on this but I can make it explicit here as well. > >> + >> + return 0; >> +} >> + >> +/* >> + * @reset_args: phandle to the GPIO provider with all the args like GPIO number >> + */ >> +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); > > So how does dumping the stack help here exactly? This is self-documenting code. dumping stack does not matter, the point is that future developers should see this lockdep before they start playing with new locks. > >> + >> + 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); >> + > > You're already using cleanup helpers above, why not here too? Would > make this function much more readable and allow you to drop all but Not sure how much it would be cleaner considering that these are not free on success. > the ida_free() here. Possibly you'd need to define the __free() > callback for of_node_put() though. > >> + 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; >> + >> + lockdep_assert_held(&reset_list_mutex); >> + >> + rcdev = NULL; >> + list_for_each_entry(r, &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; >> + } >> + } else { >> + rcdev = r; >> + break; >> + } >> + } >> + } >> + >> + return rcdev; >> +} >> + >> 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}; >> + 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)) { >> 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); > > I suggest reworking this to use cleanup.h as well. It's independent task. This is an existing code and any refactoring to cleanup or not is independent thing. Best regards, Krzysztof