linux-mips
[Top] [All Lists]

Re: [PATCH v2 1/4] clk: add common __clk_get(), __clk_put() imple

To: Sylwester Nawrocki <s.nawrocki@samsung.com>
Subject: Re: [PATCH v2 1/4] clk: add common __clk_get(), __clk_put() implementations
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
Date: Tue, 20 Aug 2013 21:30:34 +0100
Cc: linux-arm-kernel@lists.infradead.org, mturquette@linaro.org, jiada_wang@mentor.com, robherring2@gmail.com, grant.likely@linaro.org, broonie@kernel.org, vapier@gentoo.org, ralf@linux-mips.org, kyungmin.park@samsung.com, shawn.guo@linaro.org, sebastian.hesselbarth@gmail.com, LW@KARO-electronics.de, t.figa@samsung.com, g.liakhovetski@gmx.de, laurent.pinchart@ideasonboard.com, linux-kernel@vger.kernel.org, uclinux-dist-devel@blackfin.uclinux.org, linux-mips@linux-mips.org, linux-sh@vger.kernel.org
Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=caramon; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=bjVc4yo6BM6uMHNygd7YGYJLqhO4nH/xUeh7+7UXT88=; b=bnou8vjBeM/UZwyvd577zM+gWbltMJesJ3+tM72kQvu1eL7jAxKs/ZPYV/VnqNNOP/LjybvNukr9ubbRVtIH/IidV7oX9+ucWKeG4AOOSpr+3yQCUt+Px4+fW1lsYFNHwTHTYqwssT0QQdbKIrJqeUGXpYDFaGQsrwdXnuLrBew=;
In-reply-to: <1377020063-30213-2-git-send-email-s.nawrocki@samsung.com>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <1377020063-30213-1-git-send-email-s.nawrocki@samsung.com> <1377020063-30213-2-git-send-email-s.nawrocki@samsung.com>
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.5.19 (2009-01-05)
On Tue, Aug 20, 2013 at 07:34:20PM +0200, Sylwester Nawrocki wrote:
> +int __clk_get(struct clk *clk)
> +{
> +     if (WARN_ON((!clk)))
> +             return 0;

This changes the behaviour of clk_get()

> +
> +     if (!try_module_get(clk->owner))
> +             return 0;

If you want this to be safe against NULL pointers, just do this:

        if (clk && !try_module_get(clk->owner))
                return 0;

> +
> +     return 1;
> +}
> +EXPORT_SYMBOL(__clk_get);
> +
> +void __clk_put(struct clk *clk)
> +{
> +     if (!clk || IS_ERR(clk))
> +             return;
> +
> +     module_put(clk->owner);

Calling clk_put() with an error-pointer should be a Bad Thing and something
that shouldn't be encouraged, so trapping it is probably unwise.  So, just
do here:

        if (clk)
                module_put(clk->owner);

If we do have some callers of this with ERR pointers, then we could add:

        if (WARN_ON_ONCE(IS_ERR(clk)))
                return;

and remove it after a full kernel cycle or so.

<Prev in Thread] Current Thread [Next in Thread>