From patchwork Wed Dec 5 12:47:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 152895 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp9255867ljp; Wed, 5 Dec 2018 04:47:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/WQP9/EckzwQmboX72RCslMF8Q8ITA3FK9pUEyjKN7p4CCBx7/2n7qNJAb6QVq/x5hYcdW+ X-Received: by 2002:a17:902:3f81:: with SMTP id a1mr15420324pld.258.1544014076438; Wed, 05 Dec 2018 04:47:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544014076; cv=none; d=google.com; s=arc-20160816; b=K3rhRI0H6O2u+ECAZmg7z0RQ5h/DINjcnTVQ9hJGZipUFHNnpoY+Nv/H5RI4XyoqCe NOg1REuEvMjovk0VxRmj2d2VhbAPT4ktxG5PLECTKsqvrlBON6P2hmEU6/iJU/8SgZiu JuJMWfVc7YknTgyCFdjKtcZMn/JRBzvdHum2DY19ZKAZ5MpSTb2lx8BK8MZsk478Une1 3OUIGtRa7XbnHGSl+K8puSHukhBu38/VPyHGhbUt1AtAOlYMmUAzayy0UN2GolNhIs6q odlg656nbpPt/vqaKmJlmDJ3W0Bhg49a2UqaVBofSjX4Uj4tf3NGJfBo7OVXa4xxwYvO T3bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Aih5LvsfvsMhYdIrSkgjVM1Zlxek03AkpQ3jJn8pr8c=; b=Rc5uJpgr+pWwRSalBKjURe1TN+th37G6rKw3E8Di/S5N2UIGsUbqkWUze+czd8fpq8 gh6uXRp/L99/Lo24Y5yLSP8WbG2JiqOYU8LjN6/jz455U+D5wDJJPqsVOLtKa6uLDdoU 4rPWQcf3l1N9+i+tvRa6V6fefiin/uKIK4PLIUxBysvG/BHtJ+3i7MPhWAF5zNqfq/rm blfG8d9R7nkTHrHMfj5tK0BBd0n+CLKZtd2yDBqEr67/6ZmNkiQIHvJQWD2H5d2EdpVL KsBOFapdYClw189KTh/D8CEzNT/c1fO0y4CgvvDcL8zjkqSsnLVovXK57+NTlnSSNNvH McbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BD1AsJ0i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 184si18679578pgj.329.2018.12.05.04.47.56; Wed, 05 Dec 2018 04:47:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BD1AsJ0i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727935AbeLEMrz (ORCPT + 31 others); Wed, 5 Dec 2018 07:47:55 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:41422 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727919AbeLEMrw (ORCPT ); Wed, 5 Dec 2018 07:47:52 -0500 Received: by mail-lj1-f195.google.com with SMTP id k15-v6so733478ljc.8 for ; Wed, 05 Dec 2018 04:47:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Aih5LvsfvsMhYdIrSkgjVM1Zlxek03AkpQ3jJn8pr8c=; b=BD1AsJ0i9yE4A7wpFRIL3wjXaEUe0g6haVUi2mrHm3Z55B8q8ppckHHyG69pIT05sB UUgh3hFhqMBxyfLLkYe+Mk/i6ZIg2aPH7MHJYreSuLnT5puXl1xJXPuRNoQJ5EbP6UVc X6Q1zj2gJDY/lyp7B2rPrpSYhU40meZ69fnmI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Aih5LvsfvsMhYdIrSkgjVM1Zlxek03AkpQ3jJn8pr8c=; b=aA9Gr/0VdEEj7by9v4+KJCRNAH4H1h7LxhAiD3/lssDFhildVlnecAVfyrsVvuzXq2 622yC/u7oLc3ViNmEzyaZRNB8QLXW9oFptVnSP7p4y2gYUdEuidFP6C8fZUDrzK3FMOa qBQSOvEejjoUHFSM7ZVhIiYBqjEFZMtSvR40tZRl3tJ8HDMjWftM7zRTdS6sIPqWJ9Ww AyXezxxvXKOWI8r+dhjJQFqH1wpViUyNHW7ZOu19dvSlxfM1XM2eBrw2UggupZHT49An 1hN1dRHwVsILADSx9IT1iFJB6odt9FZ0LldRvNIO3AxakLQG3qOovlhbIIoU9jFaycdr x5NQ== X-Gm-Message-State: AA+aEWbjQlTt3YvYQ8iLkAVNR1Ig2PwhIKY8T5Tfx/kIq11e8d72h51B wFfS0HQFDaJiwHQc6IDbJgO4Sg== X-Received: by 2002:a2e:5703:: with SMTP id l3-v6mr129644ljb.106.1544014070213; Wed, 05 Dec 2018 04:47:50 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id e19-v6sm3797125ljf.67.2018.12.05.04.47.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Dec 2018 04:47:49 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Charles Keepax , Bartosz Golaszewski , Marek Szyprowski , Linus Walleij Subject: [PATCH 10/15 v3] gpio: devres: Handle nonexclusive GPIOs Date: Wed, 5 Dec 2018 13:47:16 +0100 Message-Id: <20181205124721.26624-11-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181205124721.26624-1-linus.walleij@linaro.org> References: <20181205124721.26624-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we get a nonexeclusive GPIO descriptor using managed resources, we should only add it to the list of managed resources once: on the first user. Augment the devm_gpiod_get_index() and devm_gpiod_get_from_of_node() calls to account for this by checking if the descriptor is already resource managed before we proceed to allocate a new resource management struct. Cc: Mark Brown Cc: Bartosz Golaszewski Cc: Marek Szyprowski Fixes: b0ce7b29bfcd ("regulator/gpio: Allow nonexclusive GPIO access") Reported-by: Marek Szyprowski Signed-off-by: Linus Walleij --- ChangeLog v1->v3: - New patch. - This fix is in response to an issue Marek saw in the fixups for resource-managed GPIO descriptors used with ena_gpiod in the regulator subsystem. - I first thought to apply it to the GPIO tree directly, but since it is not a regression it is better to put it into the regulator tree with the rest of the patches. --- drivers/gpio/gpiolib-devres.c | 50 ++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) -- 2.19.2 diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c index 01959369360b..a57e968025a8 100644 --- a/drivers/gpio/gpiolib-devres.c +++ b/drivers/gpio/gpiolib-devres.c @@ -98,15 +98,28 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, struct gpio_desc **dr; struct gpio_desc *desc; + desc = gpiod_get_index(dev, con_id, idx, flags); + if (IS_ERR(desc)) + return desc; + + /* + * For non-exclusive GPIO descriptors, check if this descriptor is + * already under resource management by this device. + */ + if (flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE) { + struct devres *dres; + + dres = devres_find(dev, devm_gpiod_release, + devm_gpiod_match, desc); + if (dres) + return desc; + } + dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *), GFP_KERNEL); - if (!dr) + if (!dr) { + gpiod_put(desc); return ERR_PTR(-ENOMEM); - - desc = gpiod_get_index(dev, con_id, idx, flags); - if (IS_ERR(desc)) { - devres_free(dr); - return desc; } *dr = desc; @@ -140,15 +153,28 @@ struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, struct gpio_desc **dr; struct gpio_desc *desc; + desc = gpiod_get_from_of_node(node, propname, index, dflags, label); + if (IS_ERR(desc)) + return desc; + + /* + * For non-exclusive GPIO descriptors, check if this descriptor is + * already under resource management by this device. + */ + if (dflags & GPIOD_FLAGS_BIT_NONEXCLUSIVE) { + struct devres *dres; + + dres = devres_find(dev, devm_gpiod_release, + devm_gpiod_match, desc); + if (dres) + return desc; + } + dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *), GFP_KERNEL); - if (!dr) + if (!dr) { + gpiod_put(desc); return ERR_PTR(-ENOMEM); - - desc = gpiod_get_from_of_node(node, propname, index, dflags, label); - if (IS_ERR(desc)) { - devres_free(dr); - return desc; } *dr = desc;