[kmod] util: fix non-static assert_cc use
diff mbox

Message ID 20170607061811.4016-1-joel@jms.id.au
State New
Headers show

Commit Message

Joel Stanley June 7, 2017, 6:18 a.m. UTC
In commit a6ede6c7ad46 (util: fix warning of equal values on logical OR)
the runtime check for EAGAIN and EWOULDBLOCK being equal was converted
into an assert.

For the case where the compiler supports _Static_assert, this is can be
called staticly. However the fallback for older compilers uses a
non-static test that needs to be called from a function context.

Move the assert into the functions that used to have the runtime check.
The test does not add any runtime overhead, so it is fine to duplicate
it.

Tested with and without HAVE_STATIC_ASSERT defined using GCC 6.3.

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 shared/util.c              | 4 ++--
 testsuite/test-testsuite.c | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

Comments

Joel Stanley June 7, 2017, noon UTC | #1
On Wed, Jun 7, 2017 at 3:48 PM, Joel Stanley <joel@jms.id.au> wrote:
> In commit a6ede6c7ad46 (util: fix warning of equal values on logical OR)
> the runtime check for EAGAIN and EWOULDBLOCK being equal was converted
> into an assert.
>
> For the case where the compiler supports _Static_assert, this is can be
> called staticly. However the fallback for older compilers uses a
> non-static test that needs to be called from a function context.
>
> Move the assert into the functions that used to have the runtime check.
> The test does not add any runtime overhead, so it is fine to duplicate
> it.
>
> Tested with and without HAVE_STATIC_ASSERT defined using GCC 6.3.
>
> Signed-off-by: Joel Stanley <joel@jms.id.au>

I just saw the git history and noticed that Thomas sent a patch fixing
this already. Excellent! Sorry for the noise.

Cheers,

Joel

> ---
>  shared/util.c              | 4 ++--
>  testsuite/test-testsuite.c | 1 +
>  2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/shared/util.c b/shared/util.c
> index 9de080aabb18..c402953b4699 100644
> --- a/shared/util.c
> +++ b/shared/util.c
> @@ -49,8 +49,6 @@ static const struct kmod_ext {
>         { }
>  };
>
> -assert_cc(EAGAIN == EWOULDBLOCK);
> -
>  /* string handling functions and memory allocations                         */
>  /* ************************************************************************ */
>
> @@ -200,6 +198,7 @@ ssize_t read_str_safe(int fd, char *buf, size_t buflen)
>  {
>         size_t todo = buflen - 1;
>         size_t done = 0;
> +       assert_cc(EAGAIN == EWOULDBLOCK);
>
>         do {
>                 ssize_t r = read(fd, buf + done, todo);
> @@ -225,6 +224,7 @@ ssize_t write_str_safe(int fd, const char *buf, size_t buflen)
>  {
>         size_t todo = buflen;
>         size_t done = 0;
> +       assert_cc(EAGAIN == EWOULDBLOCK);
>
>         do {
>                 ssize_t r = write(fd, buf + done, todo);
> diff --git a/testsuite/test-testsuite.c b/testsuite/test-testsuite.c
> index 56e73609f204..5bafc6551a23 100644
> --- a/testsuite/test-testsuite.c
> +++ b/testsuite/test-testsuite.c
> @@ -88,6 +88,7 @@ static int testsuite_rootfs_open(const struct test *t)
>  {
>         char buf[100];
>         int fd, done;
> +       assert_cc(EAGAIN == EWOULDBLOCK);
>
>         fd = open("/lib/modules/a", O_RDONLY);
>         if (fd < 0)
> --
> 2.11.0
>
--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lucas De Marchi June 8, 2017, 11:08 p.m. UTC | #2
On Wed, Jun 7, 2017 at 5:00 AM, Joel Stanley <joel@jms.id.au> wrote:
> On Wed, Jun 7, 2017 at 3:48 PM, Joel Stanley <joel@jms.id.au> wrote:
>> In commit a6ede6c7ad46 (util: fix warning of equal values on logical OR)
>> the runtime check for EAGAIN and EWOULDBLOCK being equal was converted
>> into an assert.
>>
>> For the case where the compiler supports _Static_assert, this is can be
>> called staticly. However the fallback for older compilers uses a
>> non-static test that needs to be called from a function context.
>>
>> Move the assert into the functions that used to have the runtime check.
>> The test does not add any runtime overhead, so it is fine to duplicate
>> it.
>>
>> Tested with and without HAVE_STATIC_ASSERT defined using GCC 6.3.
>>
>> Signed-off-by: Joel Stanley <joel@jms.id.au>
>
> I just saw the git history and noticed that Thomas sent a patch fixing
> this already. Excellent! Sorry for the noise.

So many people using ancient compilers... I must be missing the fun :)

Lucas De Marchi
--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joel Stanley June 9, 2017, 5:10 a.m. UTC | #3
On Fri, Jun 9, 2017 at 8:38 AM, Lucas De Marchi
<lucas.de.marchi@gmail.com> wrote:
> On Wed, Jun 7, 2017 at 5:00 AM, Joel Stanley <joel@jms.id.au> wrote:
>> On Wed, Jun 7, 2017 at 3:48 PM, Joel Stanley <joel@jms.id.au> wrote:
>>> In commit a6ede6c7ad46 (util: fix warning of equal values on logical OR)
>>> the runtime check for EAGAIN and EWOULDBLOCK being equal was converted
>>> into an assert.
>>>
>>> For the case where the compiler supports _Static_assert, this is can be
>>> called staticly. However the fallback for older compilers uses a
>>> non-static test that needs to be called from a function context.
>>>
>>> Move the assert into the functions that used to have the runtime check.
>>> The test does not add any runtime overhead, so it is fine to duplicate
>>> it.
>>>
>>> Tested with and without HAVE_STATIC_ASSERT defined using GCC 6.3.
>>>
>>> Signed-off-by: Joel Stanley <joel@jms.id.au>
>>
>> I just saw the git history and noticed that Thomas sent a patch fixing
>> this already. Excellent! Sorry for the noise.
>
> So many people using ancient compilers... I must be missing the fun :)

Yeah. Supporting groups that insist on using RHEL6.4 and gcc 4.4 is a
barrel of laughs.

:)

Cheers,

Joel
--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/shared/util.c b/shared/util.c
index 9de080aabb18..c402953b4699 100644
--- a/shared/util.c
+++ b/shared/util.c
@@ -49,8 +49,6 @@  static const struct kmod_ext {
 	{ }
 };
 
-assert_cc(EAGAIN == EWOULDBLOCK);
-
 /* string handling functions and memory allocations                         */
 /* ************************************************************************ */
 
@@ -200,6 +198,7 @@  ssize_t read_str_safe(int fd, char *buf, size_t buflen)
 {
 	size_t todo = buflen - 1;
 	size_t done = 0;
+	assert_cc(EAGAIN == EWOULDBLOCK);
 
 	do {
 		ssize_t r = read(fd, buf + done, todo);
@@ -225,6 +224,7 @@  ssize_t write_str_safe(int fd, const char *buf, size_t buflen)
 {
 	size_t todo = buflen;
 	size_t done = 0;
+	assert_cc(EAGAIN == EWOULDBLOCK);
 
 	do {
 		ssize_t r = write(fd, buf + done, todo);
diff --git a/testsuite/test-testsuite.c b/testsuite/test-testsuite.c
index 56e73609f204..5bafc6551a23 100644
--- a/testsuite/test-testsuite.c
+++ b/testsuite/test-testsuite.c
@@ -88,6 +88,7 @@  static int testsuite_rootfs_open(const struct test *t)
 {
 	char buf[100];
 	int fd, done;
+	assert_cc(EAGAIN == EWOULDBLOCK);
 
 	fd = open("/lib/modules/a", O_RDONLY);
 	if (fd < 0)