From patchwork Thu Feb 11 10:26:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 61715 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp105217lbl; Thu, 11 Feb 2016 02:26:52 -0800 (PST) X-Received: by 10.98.42.10 with SMTP id q10mr65586273pfq.73.1455186408000; Thu, 11 Feb 2016 02:26:48 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 22si7240467pfq.57.2016.02.11.02.26.47; Thu, 11 Feb 2016 02:26:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751374AbcBKK0q (ORCPT + 4 others); Thu, 11 Feb 2016 05:26:46 -0500 Received: from mail-wm0-f42.google.com ([74.125.82.42]:34385 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751149AbcBKK0p (ORCPT ); Thu, 11 Feb 2016 05:26:45 -0500 Received: by mail-wm0-f42.google.com with SMTP id 128so14686171wmz.1 for ; Thu, 11 Feb 2016 02:26:45 -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; bh=Kd1TAMRpKo5pF3+O7VlHbWejRTDrGLiGGXp+mHevslw=; b=YjAE4bpYSnXyoJgVaxQc47tsIb58YVYqMgpT3tnRfOZwiUfZ/NiSBofYgRts0w6tCN dr+jBCMpIY/lL8sblHgXOlo+UJP5fucVdkJQjiQlAYg1EOsPXVumDRXFt0MDpSIxGGOr kT2SyTgJM1PkbZR65839BTHnlROAEjYzG9syU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Kd1TAMRpKo5pF3+O7VlHbWejRTDrGLiGGXp+mHevslw=; b=Kr5TFH9JlkRLWzMVbmAXGn1Kjtm6AaxVllmArwLHsWjbKqZz9K/3E+FnjG89ImF3Lv 3VPsUVNAZsKAvFTKExencAjC5u+ZUcBRfXwW77h0Q7YIpQPd/dycwLHuVLjGNXYKWVxS 3fvUo2tO4HBSy9PjhL1AuAOO0CbzjeUtPevuLCG2POhZDR3WsEoASx1I4mJgrhcbfhC/ E2KhYcrxBkmq6E1549KjP2VZ0Rsxt+Tze2+ERQYSRkX1ikdLoLS2zoA3m0qGLo3iHm4s hwdgwoNeGcN1ZYiC208pKwDivVSYBtTUnv/EVNemvV/COGWNMFNjNaYOabKRCfIGVHV4 n+/g== X-Gm-Message-State: AG10YOQW5AMz2xutzZkKmy3RjqQn0SigeshpPOKHgfnJGaCSKJ0yAfxuHDgiEkuPJgMkFW3r X-Received: by 10.28.125.77 with SMTP id y74mr16027534wmc.21.1455186404715; Thu, 11 Feb 2016 02:26:44 -0800 (PST) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id jo6sm6856241wjb.48.2016.02.11.02.26.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Feb 2016 02:26:43 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot , Johan Hovold , Michael Welling , Markus Pargmann Cc: Bamvor Jian Zhang , Grant Likely , Linus Walleij Subject: [PATCH 5/6] gpio: reference count the gpio device for each desc Date: Thu, 11 Feb 2016 11:26:22 +0100 Message-Id: <1455186383-28004-6-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1455186383-28004-1-git-send-email-linus.walleij@linaro.org> References: <1455186383-28004-1-git-send-email-linus.walleij@linaro.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Every time a descriptor is retrieved from the gpiolib, we issue module_get() to reference count the module supplying the GPIOs. We also need to call device_get() and device_put() as we also reference the backing gpio_device when doing this. Since the sysfs GPIO interface is using gpiod_get() this will also reference count the sysfs requests until all GPIOs are unexported. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index cbc9c764a7fb..157ab40d19b1 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1205,6 +1205,8 @@ int gpiod_request(struct gpio_desc *desc, const char *label) status = __gpiod_request(desc, label); if (status < 0) module_put(gdev->owner); + else + get_device(&gdev->dev); } if (status) @@ -1248,10 +1250,12 @@ static bool __gpiod_free(struct gpio_desc *desc) void gpiod_free(struct gpio_desc *desc) { - if (desc && __gpiod_free(desc)) + if (desc && desc->gdev && __gpiod_free(desc)) { module_put(desc->gdev->owner); - else + put_device(&desc->gdev->dev); + } else { WARN_ON(extra_checks); + } } /**