From patchwork Tue Sep 12 10:07:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 722354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53726CA0EC3 for ; Tue, 12 Sep 2023 10:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233687AbjILKIS (ORCPT ); Tue, 12 Sep 2023 06:08:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233947AbjILKHr (ORCPT ); Tue, 12 Sep 2023 06:07:47 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50D761BB for ; Tue, 12 Sep 2023 03:07:43 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-31f737b8b69so4949948f8f.3 for ; Tue, 12 Sep 2023 03:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513262; x=1695118062; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lK3han4CVz5LHUOmuD0tfQkarnpldPL2EDThSOp4uoo=; b=hKkpj9ebeywUDPpZfqGwEIXFBQG+IhXqeLEzQJ9UHbyxA+lMwhhFu56ute+bcz9UFy 7TcTbGdAlXpHOjFqRn95P/fTqi7YqHot1pScejxHLqoEa9VrPINyM7SIiSESr2cUwYjQ UNgIBM/P9BwBFa5IJyAaEAUbx5ae4dQrYCKDPzMl0/b5IkijYDqJMWzISZmpXq6xZph7 AHoegF2nXvUvs7kVPfHqEuVsElkLKDkmvUf7EuJPdotUqYOQAD75WmlxP2h1MSvmuuRU 9LNnX4ejEWkf/Tu3uDxtI4YQp7zb2H8pzc4yVa3cCps3iOmKTbAqaGPcTk/+wrdpnn/D 4phg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513262; x=1695118062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lK3han4CVz5LHUOmuD0tfQkarnpldPL2EDThSOp4uoo=; b=fdLWFvg8e7MKJEtGXi+mPLrW8BAbYy1pAjCxhF4KGmPp9fTOcwUB7t0U4WPAb4YGV2 I4JFeWN8WjNoAXAmRcNG8XHXLl3Uqt56ac+SISONNX8EVNvwtsgdtTNS4q5o7dqQKRpC AcoSNcF+Dav/0of2kkxF9baIiT3SOPVlY4HSDJ1J8TQFwfDQnIYy//knkzkdrdoCrfDA 1gKbpx5A4vvgop1CGro8ypw2SIu5RtN+VR3phtv71rhLCYu7IetGsjdVgGDqLaR9FhNV NXNoWjA/2+As1dXOeF0U0c6iXiXDSVf6jaHDFsrPODaKND7dL9QX6CjCOieBB6ZqLnYF xCiw== X-Gm-Message-State: AOJu0YwasWb2MMV9XYvpv6QOpRccv1gnV2n5ARREDasiEwSo84VDew8A ZLRpNyF7tug+9cgivsi5UEVtTg== X-Google-Smtp-Source: AGHT+IHQaoqjxtbbCR/GgutlU02aJZq/Tzbxpk5PviNsqzIRCPSQARYZbf/TjHfrpO4UdF1ds2ob1Q== X-Received: by 2002:a5d:4ac3:0:b0:317:6cc7:6b21 with SMTP id y3-20020a5d4ac3000000b003176cc76b21mr9864728wrs.69.1694513261863; Tue, 12 Sep 2023 03:07:41 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:41 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 07/11] gpiolib: replace find_chip_by_name() with gpio_device_find_by_label() Date: Tue, 12 Sep 2023 12:07:23 +0200 Message-Id: <20230912100727.23197-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Remove all remaining uses of find_chip_by_name() (and subsequently: gpiochip_find()) from gpiolib.c and use the new gpio_device_find_by_label() instead. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 224e0d330009..a10d1d663524 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1144,18 +1144,6 @@ struct gpio_device *gpio_device_find_by_label(const char *label) } EXPORT_SYMBOL_GPL(gpio_device_find_by_label); -static int gpiochip_match_name(struct gpio_chip *gc, void *data) -{ - const char *name = data; - - return !strcmp(gc->label, name); -} - -static struct gpio_chip *find_chip_by_name(const char *name) -{ - return gpiochip_find((void *)name, gpiochip_match_name); -} - /** * gpio_device_get() - Increase the reference count of this GPIO device * @gdev: GPIO device to increase the refcount for @@ -3907,21 +3895,22 @@ EXPORT_SYMBOL_GPL(gpiod_remove_lookup_table); */ void gpiod_add_hogs(struct gpiod_hog *hogs) { - struct gpio_chip *gc; struct gpiod_hog *hog; mutex_lock(&gpio_machine_hogs_mutex); for (hog = &hogs[0]; hog->chip_label; hog++) { + struct gpio_device *gdev __free(gpio_device_put) = NULL; + list_add_tail(&hog->list, &gpio_machine_hogs); /* * The chip may have been registered earlier, so check if it * exists and, if so, try to hog the line now. */ - gc = find_chip_by_name(hog->chip_label); - if (gc) - gpiochip_machine_hog(gc, hog); + gdev = gpio_device_find_by_label(hog->chip_label); + if (gdev) + gpiochip_machine_hog(gpio_device_get_chip(gdev), hog); } mutex_unlock(&gpio_machine_hogs_mutex); @@ -3976,13 +3965,16 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, struct gpio_desc *desc = ERR_PTR(-ENOENT); struct gpiod_lookup_table *table; struct gpiod_lookup *p; + struct gpio_chip *gc; table = gpiod_find_lookup_table(dev); if (!table) return desc; for (p = &table->table[0]; p->key; p++) { - struct gpio_chip *gc; + struct gpio_device *gdev __free(gpio_device_put) = NULL; + + gc = gpio_device_get_chip(gdev); /* idx must always match exactly */ if (p->idx != idx) @@ -4004,9 +3996,8 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, return ERR_PTR(-EPROBE_DEFER); } - gc = find_chip_by_name(p->key); - - if (!gc) { + gdev = gpio_device_find_by_label(p->key); + if (!gdev) { /* * As the lookup table indicates a chip with * p->key should exist, assume it may @@ -4022,7 +4013,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, if (gc->ngpio <= p->chip_hwnum) { dev_err(dev, "requested GPIO %u (%u) is out of range [0..%u] for chip %s\n", - idx, p->chip_hwnum, gc->ngpio - 1, + idx, p->chip_hwnum, gdev->chip->ngpio - 1, gc->label); return ERR_PTR(-EINVAL); }