All of lore.kernel.org
 help / color / mirror / Atom feed
From: Antonio Ospite <ospite@studenti.unina.it>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Russell King - ARM Linux <linux@arm.linux.org.uk>,
	linux-mmc@vger.kernel.org, openezx-devel@lists.openezx.org,
	Chris Ball <cjb@laptop.org>,
	linux-arm-kernel@lists.infradead.org,
	Linus Walleij <linus.walleij@linaro.org>
Subject: Re: [PATCH] pxamci: remove an ifdef about CONFIG_REGULATOR
Date: Tue, 10 May 2011 22:02:14 +0200	[thread overview]
Message-ID: <20110510220214.916621d1.ospite@studenti.unina.it> (raw)
In-Reply-To: <20110509203612.GC21323@opensource.wolfsonmicro.com>


[-- Attachment #1.1: Type: text/plain, Size: 1410 bytes --]

On Mon, 9 May 2011 22:36:12 +0200
Mark Brown <broonie@opensource.wolfsonmicro.com> wrote:

> On Mon, May 09, 2011 at 09:23:25PM +0100, Russell King - ARM Linux wrote:
> 
> > NAK.  This has been proposed before, and rejected.  See the comments
> > against the original proposal:
> 
> > http://www.arm.linux.org.uk/developer/patches/viewpatch.php?id=6525/1
> 
> Hrm, this looks like the bodge we're doing for !REGULATOR isn't actually
> helping here unless we do a NULL || IS_ERR() in the error check.  The
> ifdefs are certainly fail.
> 

[Adding Linus Walleij to CC as he was the author of a similar NAKed
patch]

I was blindly trusting code already in mainline again, and for that I
apologize, I finally took the time to look at the implementation
of IS_ERR() and test its use, and being IS_ERR(NULL) true it is not what
we want indeed, see the attached test program.

So, I am going to remove the ifdefs anyway but use IS_ERR_OR_NULL();
how does that sound? Am I still missing anything?
Or changing the regulator_get() stub to return an error (-ENOSYS?) might
be worth it?

Thanks Russel for pointing out the issue BTW.

Thanks,
   Antonio

-- 
Antonio Ospite
http://ao2.it

PGP public key ID: 0x4553B001

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: IS_ERR_regulator_get.c --]
[-- Type: text/x-csrc; name="IS_ERR_regulator_get.c", Size: 1662 bytes --]

#include <stdio.h>

/* from /include/linux/compiler.h */
#define likely_notrace(x)       __builtin_expect(!!(x), 1)
#define unlikely_notrace(x)     __builtin_expect(!!(x), 0)

#define likely(x)   likely_notrace(x)
#define unlikely(x) unlikely_notrace(x)

/* from include/linux/compiler-gcc4.h */
#define __must_check            __attribute__((warn_unused_result))

/* From include/linux/err.h */
#define MAX_ERRNO       4095

#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)

static inline long __must_check IS_ERR(const void *ptr)
{

	return IS_ERR_VALUE((unsigned long)ptr);
}

static inline long __must_check IS_ERR_OR_NULL(const void *ptr)
{
	return !ptr || IS_ERR_VALUE((unsigned long)ptr);
}


/* Mimic regulator_get() when CONFIG_REGULATOR is defined */
unsigned long *regulator_get_full()
{
	unsigned long *ptr;

	return ptr;
}

/* Mimic regulator_get() when CONFIG_REGULATOR is NOT defined */
unsigned long *regulator_get_stub()
{
	return NULL; /* or maybe return -ENOSYS; ? */
}

int main(void)
{
	unsigned long *vcc = NULL;

	vcc = regulator_get_full();
	if (IS_ERR(vcc))
		printf("full: IS_ERR         = true\n");
	else
		printf("full: IS_ERR         = false\n");

	if (IS_ERR_OR_NULL(vcc))
		printf("full: IS_ERR_OR_NULL = true\n");
	else
		printf("full: IS_ERR_OR_NULL = false\n");


	vcc = regulator_get_stub();
	if (IS_ERR(vcc))
		printf("stub: IS_ERR         = true\n");
	else
		printf("stub: IS_ERR         = false\n");

	if (IS_ERR_OR_NULL(vcc))
		printf("stub: IS_ERR_OR_NULL = true\n");
	else
		printf("stub: IS_ERR_OR_NULL = false\n");

	return 0;
}

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: ospite@studenti.unina.it (Antonio Ospite)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] pxamci: remove an ifdef about CONFIG_REGULATOR
Date: Tue, 10 May 2011 22:02:14 +0200	[thread overview]
Message-ID: <20110510220214.916621d1.ospite@studenti.unina.it> (raw)
In-Reply-To: <20110509203612.GC21323@opensource.wolfsonmicro.com>

On Mon, 9 May 2011 22:36:12 +0200
Mark Brown <broonie@opensource.wolfsonmicro.com> wrote:

> On Mon, May 09, 2011 at 09:23:25PM +0100, Russell King - ARM Linux wrote:
> 
> > NAK.  This has been proposed before, and rejected.  See the comments
> > against the original proposal:
> 
> > http://www.arm.linux.org.uk/developer/patches/viewpatch.php?id=6525/1
> 
> Hrm, this looks like the bodge we're doing for !REGULATOR isn't actually
> helping here unless we do a NULL || IS_ERR() in the error check.  The
> ifdefs are certainly fail.
> 

[Adding Linus Walleij to CC as he was the author of a similar NAKed
patch]

I was blindly trusting code already in mainline again, and for that I
apologize, I finally took the time to look at the implementation
of IS_ERR() and test its use, and being IS_ERR(NULL) true it is not what
we want indeed, see the attached test program.

So, I am going to remove the ifdefs anyway but use IS_ERR_OR_NULL();
how does that sound? Am I still missing anything?
Or changing the regulator_get() stub to return an error (-ENOSYS?) might
be worth it?

Thanks Russel for pointing out the issue BTW.

Thanks,
   Antonio

-- 
Antonio Ospite
http://ao2.it

PGP public key ID: 0x4553B001

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: IS_ERR_regulator_get.c
Type: text/x-csrc
Size: 1590 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110510/12e659f9/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110510/12e659f9/attachment.sig>

  reply	other threads:[~2011-05-10 20:02 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-09 20:11 [PATCH] pxamci: remove an ifdef about CONFIG_REGULATOR Antonio Ospite
2011-05-09 20:11 ` Antonio Ospite
2011-05-09 20:15 ` Mark Brown
2011-05-09 20:15   ` Mark Brown
2011-05-09 20:23 ` Russell King - ARM Linux
2011-05-09 20:23   ` Russell King - ARM Linux
2011-05-09 20:36   ` Mark Brown
2011-05-09 20:36     ` Mark Brown
2011-05-10 20:02     ` Antonio Ospite [this message]
2011-05-10 20:02       ` Antonio Ospite
2011-05-10 20:32       ` Russell King - ARM Linux
2011-05-10 20:32         ` Russell King - ARM Linux
2011-05-10 20:36       ` Mark Brown
2011-05-10 20:36         ` Mark Brown
2011-05-11 10:19         ` [PATCH v2 1/2] pxamci: remove the ifdef CONFIG_REGULATOR Antonio Ospite
2011-05-11 10:19           ` Antonio Ospite
2011-05-11 13:07           ` Mark Brown
2011-05-11 13:07             ` Mark Brown
2011-05-11 14:41           ` Chris Ball
2011-05-11 14:41             ` Chris Ball
2011-05-11 20:19             ` Antonio Ospite
2011-05-11 20:19               ` Antonio Ospite
2011-05-11 10:19         ` [PATCH 2/2] pxamci: fix coding style for multi statement conditionals Antonio Ospite
2011-05-11 10:19           ` Antonio Ospite
2011-05-11 10:26       ` [PATCH] pxamci: remove an ifdef about CONFIG_REGULATOR Antonio Ospite
2011-05-11 10:26         ` Antonio Ospite
2011-05-10 11:59 ` Sergei Shtylyov
2011-05-10 11:59   ` Sergei Shtylyov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110510220214.916621d1.ospite@studenti.unina.it \
    --to=ospite@studenti.unina.it \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=cjb@laptop.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=openezx-devel@lists.openezx.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.