From mboxrd@z Thu Jan 1 00:00:00 1970 From: Philipp Zabel Subject: [PATCH v5 1/6] reset: use kref for reference counting Date: Thu, 1 Jun 2017 18:51:58 +0200 Message-ID: <20170601165203.15315-2-p.zabel@pengutronix.de> References: <20170601165203.15315-1-p.zabel@pengutronix.de> Return-path: In-Reply-To: <20170601165203.15315-1-p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> Sender: linux-tegra-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: Vivek Gautam , Jon Hunter , Felipe Balbi , Greg Kroah-Hartman , Thierry Reding , linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-arm-msm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Philipp Zabel List-Id: linux-tegra@vger.kernel.org Use kref for reference counting and enjoy the advantages of refcount_t. Signed-off-by: Philipp Zabel --- drivers/reset/core.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index cd739d2fa1603..0090784ff4105 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -40,7 +41,7 @@ struct reset_control { struct reset_controller_dev *rcdev; struct list_head list; unsigned int id; - unsigned int refcnt; + struct kref refcnt; bool shared; atomic_t deassert_count; atomic_t triggered_count; @@ -288,7 +289,7 @@ static struct reset_control *__reset_control_get_internal( if (WARN_ON(!rstc->shared || !shared)) return ERR_PTR(-EBUSY); - rstc->refcnt++; + kref_get(&rstc->refcnt); return rstc; } } @@ -302,18 +303,18 @@ static struct reset_control *__reset_control_get_internal( rstc->rcdev = rcdev; list_add(&rstc->list, &rcdev->reset_control_head); rstc->id = index; - rstc->refcnt = 1; + kref_init(&rstc->refcnt); rstc->shared = shared; return rstc; } -static void __reset_control_put_internal(struct reset_control *rstc) +static void __reset_control_release(struct kref *kref) { - lockdep_assert_held(&reset_list_mutex); + struct reset_control *rstc = container_of(kref, struct reset_control, + refcnt); - if (--rstc->refcnt) - return; + lockdep_assert_held(&reset_list_mutex); module_put(rstc->rcdev->owner); @@ -321,6 +322,13 @@ static void __reset_control_put_internal(struct reset_control *rstc) kfree(rstc); } +static void __reset_control_put_internal(struct reset_control *rstc) +{ + lockdep_assert_held(&reset_list_mutex); + + kref_put(&rstc->refcnt, __reset_control_release); +} + struct reset_control *__of_reset_control_get(struct device_node *node, const char *id, int index, bool shared, bool optional) @@ -400,7 +408,6 @@ EXPORT_SYMBOL_GPL(__reset_control_get); * reset_control_put - free the reset controller * @rstc: reset controller */ - void reset_control_put(struct reset_control *rstc) { if (IS_ERR_OR_NULL(rstc)) -- 2.11.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751974AbdFAQw0 (ORCPT ); Thu, 1 Jun 2017 12:52:26 -0400 Received: from metis.ext.4.pengutronix.de ([92.198.50.35]:49795 "EHLO metis.ext.4.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751760AbdFAQwY (ORCPT ); Thu, 1 Jun 2017 12:52:24 -0400 From: Philipp Zabel To: linux-kernel@vger.kernel.org Cc: Vivek Gautam , Jon Hunter , Felipe Balbi , Greg Kroah-Hartman , Thierry Reding , linux-tegra@vger.kernel.org, linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org, Philipp Zabel Subject: [PATCH v5 1/6] reset: use kref for reference counting Date: Thu, 1 Jun 2017 18:51:58 +0200 Message-Id: <20170601165203.15315-2-p.zabel@pengutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170601165203.15315-1-p.zabel@pengutronix.de> References: <20170601165203.15315-1-p.zabel@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use kref for reference counting and enjoy the advantages of refcount_t. Signed-off-by: Philipp Zabel --- drivers/reset/core.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index cd739d2fa1603..0090784ff4105 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -40,7 +41,7 @@ struct reset_control { struct reset_controller_dev *rcdev; struct list_head list; unsigned int id; - unsigned int refcnt; + struct kref refcnt; bool shared; atomic_t deassert_count; atomic_t triggered_count; @@ -288,7 +289,7 @@ static struct reset_control *__reset_control_get_internal( if (WARN_ON(!rstc->shared || !shared)) return ERR_PTR(-EBUSY); - rstc->refcnt++; + kref_get(&rstc->refcnt); return rstc; } } @@ -302,18 +303,18 @@ static struct reset_control *__reset_control_get_internal( rstc->rcdev = rcdev; list_add(&rstc->list, &rcdev->reset_control_head); rstc->id = index; - rstc->refcnt = 1; + kref_init(&rstc->refcnt); rstc->shared = shared; return rstc; } -static void __reset_control_put_internal(struct reset_control *rstc) +static void __reset_control_release(struct kref *kref) { - lockdep_assert_held(&reset_list_mutex); + struct reset_control *rstc = container_of(kref, struct reset_control, + refcnt); - if (--rstc->refcnt) - return; + lockdep_assert_held(&reset_list_mutex); module_put(rstc->rcdev->owner); @@ -321,6 +322,13 @@ static void __reset_control_put_internal(struct reset_control *rstc) kfree(rstc); } +static void __reset_control_put_internal(struct reset_control *rstc) +{ + lockdep_assert_held(&reset_list_mutex); + + kref_put(&rstc->refcnt, __reset_control_release); +} + struct reset_control *__of_reset_control_get(struct device_node *node, const char *id, int index, bool shared, bool optional) @@ -400,7 +408,6 @@ EXPORT_SYMBOL_GPL(__reset_control_get); * reset_control_put - free the reset controller * @rstc: reset controller */ - void reset_control_put(struct reset_control *rstc) { if (IS_ERR_OR_NULL(rstc)) -- 2.11.0