Re: [PATCH] regulator: Fix and simplify debugfs support

From: Hillf Danton
Date: Sun Feb 19 2012 - 02:51:25 EST


On Sun, Feb 19, 2012 at 3:28 PM, Stephen Boyd <sboyd@xxxxxxxxxxxxxx> wrote:
> If CONFIG_DEBUG_FS=y debugfs functions will never return an
> ERR_PTR. Instead they'll return NULL. The intent is to remove
> ifdefs in calling code.
>

Unfortunately there is no decrement in #ifdefs observed:(

> Instead of checking for an ERR_PTR check for NULL. This simplifies
> the code and also fixes an error check that would never have
> worked otherwise. While we're here modernize the code to use
> S_IRUGO instead of 0444.
>
> Signed-off-by: Stephen Boyd <sboyd@xxxxxxxxxxxxxx>
> ---
>
> If we're willing to sacrifice a pointer per rdev we can remove the
> ifdefs and the compiler should be able to optimize away the dead
> code.
>
> Âdrivers/regulator/core.c | Â 15 +++++----------
> Â1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index e9a83f8..f20696d 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -1145,9 +1145,8 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
> Â#ifdef CONFIG_DEBUG_FS
> Â Â Â Âregulator->debugfs = debugfs_create_dir(regulator->supply_name,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Ârdev->debugfs);
> - Â Â Â if (IS_ERR_OR_NULL(regulator->debugfs)) {
> + Â Â Â if (!regulator->debugfs) {
> Â Â Â Â Â Â Â Ârdev_warn(rdev, "Failed to create debugfs directory\n");
> - Â Â Â Â Â Â Â regulator->debugfs = NULL;
> Â Â Â Â} else {
> Â Â Â Â Â Â Â Âdebugfs_create_u32("uA_load", 0444, regulator->debugfs,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &regulator->uA_load);
> @@ -2712,9 +2711,8 @@ static void rdev_init_debugfs(struct regulator_dev *rdev)
> Â{
> Â#ifdef CONFIG_DEBUG_FS
> Â Â Â Ârdev->debugfs = debugfs_create_dir(rdev_get_name(rdev), debugfs_root);
> - Â Â Â if (IS_ERR(rdev->debugfs) || !rdev->debugfs) {
> + Â Â Â if (!rdev->debugfs) {
> Â Â Â Â Â Â Â Ârdev_warn(rdev, "Failed to create debugfs directory\n");
> - Â Â Â Â Â Â Â rdev->debugfs = NULL;
> Â Â Â Â Â Â Â Âreturn;
> Â Â Â Â}
>
> @@ -3129,13 +3127,10 @@ static int __init regulator_init(void)
>
> Â#ifdef CONFIG_DEBUG_FS
> Â Â Â Âdebugfs_root = debugfs_create_dir("regulator", NULL);
> - Â Â Â if (IS_ERR(debugfs_root) || !debugfs_root) {
> + Â Â Â if (!debugfs_root)
> Â Â Â Â Â Â Â Âpr_warn("regulator: Failed to create debugfs directory\n");
> - Â Â Â Â Â Â Â debugfs_root = NULL;
> - Â Â Â }
> -
> - Â Â Â if (IS_ERR(debugfs_create_file("supply_map", 0444, debugfs_root,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂNULL, &supply_map_fops)))
> + Â Â Â else if (!debugfs_create_file("supply_map", S_IRUGO, debugfs_root,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂNULL, &supply_map_fops))
> Â Â Â Â Â Â Â Âpr_warn("regulator: Failed to create supplies debugfs\n");
> Â#endif
>
> --
> Sent by an employee of the Qualcomm Innovation Center, Inc.
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/