linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/10] kdbus: macros fixes
@ 2015-06-09 20:59 Sergei Zviagintsev
  2015-06-09 20:59 ` [PATCH v2 01/10] kdbus: fix operator precedence issues in item macros Sergei Zviagintsev
                   ` (11 more replies)
  0 siblings, 12 replies; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-09 20:59 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni
  Cc: linux-kernel, Sergei Zviagintsev

Fix type conversion and style issues in item macros.

First submission was in 2 separate emails:
https://lkml.kernel.org/g/1433414370-17557-1-git-send-email-sergei@s15v.net
https://lkml.kernel.org/g/1433414370-17557-2-git-send-email-sergei@s15v.net

Changes in v2:

 - fixed similar type cast issue in KDBUS_ITEMS_END macro
 - all arguments in iteration macros are enclosed in parentheses,
   instead of using loop cursor without them
 - summary phrases and commit messages updated
 - documentation updates are excluded to their own patches
 - added fixes for samples/kdbus
 - added fixes for selftests/kdbus


Sergei Zviagintsev (10):
  kdbus: fix operator precedence issues in item macros
  kdbus: use parentheses uniformly in KDBUS_ITEMS_FOREACH macro
  Documentation/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT
    macro
  Documentation/kdbus: use parentheses uniformly in KDBUS_ITEM_FOREACH
    macro
  selftests/kdbus: fix trivial style issues
  selftests/kdbus: fix precedence issues in macros
  selftests/kdbus: use parentheses in iteration macros uniformly
  samples/kdbus: add whitespace
  samples/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro
  samples/kdbus: use parentheses uniformly in KDBUS_FOREACH macro

 Documentation/kdbus/kdbus.item.xml         |  6 +++---
 ipc/kdbus/item.h                           | 10 ++++-----
 samples/kdbus/kdbus-api.h                  |  6 +++---
 tools/testing/selftests/kdbus/kdbus-enum.h |  1 +
 tools/testing/selftests/kdbus/kdbus-util.c |  2 +-
 tools/testing/selftests/kdbus/kdbus-util.h | 33 ++++++++++++++----------------
 6 files changed, 28 insertions(+), 30 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 01/10] kdbus: fix operator precedence issues in item macros
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
@ 2015-06-09 20:59 ` Sergei Zviagintsev
  2015-06-10 13:44   ` David Herrmann
  2015-06-09 21:00 ` [PATCH v2 02/10] kdbus: use parentheses uniformly in KDBUS_ITEMS_FOREACH macro Sergei Zviagintsev
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-09 20:59 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni
  Cc: linux-kernel, Sergei Zviagintsev

`_i' argument in KDBUS_ITEM_NEXT and KDBUS_ITEMS_END macros is not
enclosed into parentheses when the cast operator is applied, which
leads to improper type conversion if `_i' is supplied as a complex
expression, e.g.

    KDBUS_ITEM_NEXT(condition ? a : b)

KDBUS_ITEMS_SIZE macro has similar issue, missing parentheses around
`_h' when using indirection operator.

Use parentheses properly to guarantee right precedence.

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
 ipc/kdbus/item.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ipc/kdbus/item.h b/ipc/kdbus/item.h
index eeefd8beac3b..32909e2e7954 100644
--- a/ipc/kdbus/item.h
+++ b/ipc/kdbus/item.h
@@ -21,8 +21,8 @@
 #include "util.h"
 
 /* generic access and iterators over a stream of items */
-#define KDBUS_ITEM_NEXT(_i) (typeof(_i))(((u8 *)_i) + KDBUS_ALIGN8((_i)->size))
-#define KDBUS_ITEMS_SIZE(_h, _is) ((_h)->size - offsetof(typeof(*_h), _is))
+#define KDBUS_ITEM_NEXT(_i) (typeof(_i))((u8 *)(_i) + KDBUS_ALIGN8((_i)->size))
+#define KDBUS_ITEMS_SIZE(_h, _is) ((_h)->size - offsetof(typeof(*(_h)), _is))
 #define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
 #define KDBUS_ITEM_SIZE(_s) KDBUS_ALIGN8(KDBUS_ITEM_HEADER_SIZE + (_s))
 #define KDBUS_ITEM_PAYLOAD_SIZE(_i) ((_i)->size - KDBUS_ITEM_HEADER_SIZE)
@@ -40,7 +40,7 @@
 	 (u8 *)(_i) >= (u8 *)(_is))
 
 #define KDBUS_ITEMS_END(_i, _is, _s)					\
-	((u8 *)_i == ((u8 *)(_is) + KDBUS_ALIGN8(_s)))
+	((u8 *)(_i) == ((u8 *)(_is) + KDBUS_ALIGN8(_s)))
 
 /**
  * struct kdbus_item_header - Describes the fix part of an item
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 02/10] kdbus: use parentheses uniformly in KDBUS_ITEMS_FOREACH macro
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
  2015-06-09 20:59 ` [PATCH v2 01/10] kdbus: fix operator precedence issues in item macros Sergei Zviagintsev
@ 2015-06-09 21:00 ` Sergei Zviagintsev
  2015-06-10 13:46   ` David Herrmann
  2015-06-09 21:00 ` [PATCH v2 03/10] Documentation/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro Sergei Zviagintsev
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-09 21:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni
  Cc: linux-kernel, Sergei Zviagintsev

Enclose all arguments into parentheses to stay consistent across the
whole macro.

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
 ipc/kdbus/item.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ipc/kdbus/item.h b/ipc/kdbus/item.h
index 32909e2e7954..bca63b4e6e80 100644
--- a/ipc/kdbus/item.h
+++ b/ipc/kdbus/item.h
@@ -28,10 +28,10 @@
 #define KDBUS_ITEM_PAYLOAD_SIZE(_i) ((_i)->size - KDBUS_ITEM_HEADER_SIZE)
 
 #define KDBUS_ITEMS_FOREACH(_i, _is, _s)				\
-	for (_i = _is;							\
+	for ((_i) = (_is);						\
 	     ((u8 *)(_i) < (u8 *)(_is) + (_s)) &&			\
 	       ((u8 *)(_i) >= (u8 *)(_is));				\
-	     _i = KDBUS_ITEM_NEXT(_i))
+	     (_i) = KDBUS_ITEM_NEXT(_i))
 
 #define KDBUS_ITEM_VALID(_i, _is, _s)					\
 	((_i)->size >= KDBUS_ITEM_HEADER_SIZE &&			\
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 03/10] Documentation/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
  2015-06-09 20:59 ` [PATCH v2 01/10] kdbus: fix operator precedence issues in item macros Sergei Zviagintsev
  2015-06-09 21:00 ` [PATCH v2 02/10] kdbus: use parentheses uniformly in KDBUS_ITEMS_FOREACH macro Sergei Zviagintsev
@ 2015-06-09 21:00 ` Sergei Zviagintsev
  2015-06-10 14:03   ` David Herrmann
  2015-06-09 21:00 ` [PATCH v2 04/10] Documentation/kdbus: use parentheses uniformly in KDBUS_ITEM_FOREACH macro Sergei Zviagintsev
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-09 21:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni
  Cc: linux-kernel, Sergei Zviagintsev

`item' argument in KDBUS_ITEM_NEXT macro example is not enclosed into
parentheses when the cast operator is applied, which leads to improper
type conversion if `item' is supplied as a complex expression, e.g.

    KDBUS_ITEM_NEXT(condition ? a : b)

Use parentheses properly to guarantee right precedence.

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
 Documentation/kdbus/kdbus.item.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/kdbus/kdbus.item.xml b/Documentation/kdbus/kdbus.item.xml
index 09f8b903116f..b0eeeef995af 100644
--- a/Documentation/kdbus/kdbus.item.xml
+++ b/Documentation/kdbus/kdbus.item.xml
@@ -69,7 +69,7 @@
 #define KDBUS_ALIGN8(val) (((val) + 7) & ~7)
 
 #define KDBUS_ITEM_NEXT(item) \
-    (typeof(item))(((uint8_t *)item) + KDBUS_ALIGN8((item)->size))
+    (typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))
 
 #define KDBUS_ITEM_FOREACH(item, head, first)                      \
     for (item = (head)->first;                                     \
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 04/10] Documentation/kdbus: use parentheses uniformly in KDBUS_ITEM_FOREACH macro
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
                   ` (2 preceding siblings ...)
  2015-06-09 21:00 ` [PATCH v2 03/10] Documentation/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro Sergei Zviagintsev
@ 2015-06-09 21:00 ` Sergei Zviagintsev
  2015-06-10 14:03   ` David Herrmann
  2015-06-09 21:00 ` [PATCH v2 05/10] selftests/kdbus: fix trivial style issues Sergei Zviagintsev
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-09 21:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni
  Cc: linux-kernel, Sergei Zviagintsev

Enclose all arguments into parentheses to stay consistent across the
whole macro.

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
 Documentation/kdbus/kdbus.item.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/kdbus/kdbus.item.xml b/Documentation/kdbus/kdbus.item.xml
index b0eeeef995af..ee09dfa443b8 100644
--- a/Documentation/kdbus/kdbus.item.xml
+++ b/Documentation/kdbus/kdbus.item.xml
@@ -72,10 +72,10 @@
     (typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))
 
 #define KDBUS_ITEM_FOREACH(item, head, first)                      \
-    for (item = (head)->first;                                     \
+    for ((item) = (head)->first;                                   \
          ((uint8_t *)(item) < (uint8_t *)(head) + (head)->size) && \
           ((uint8_t *)(item) >= (uint8_t *)(head));                \
-         item = KDBUS_ITEM_NEXT(item))
+         (item) = KDBUS_ITEM_NEXT(item))
       ]]></programlisting>
     </refsect2>
   </refsect1>
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 05/10] selftests/kdbus: fix trivial style issues
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
                   ` (3 preceding siblings ...)
  2015-06-09 21:00 ` [PATCH v2 04/10] Documentation/kdbus: use parentheses uniformly in KDBUS_ITEM_FOREACH macro Sergei Zviagintsev
@ 2015-06-09 21:00 ` Sergei Zviagintsev
  2015-06-10 14:05   ` David Herrmann
  2015-06-09 21:00 ` [PATCH v2 06/10] selftests/kdbus: fix precedence issues in macros Sergei Zviagintsev
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-09 21:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni
  Cc: linux-kernel, Sergei Zviagintsev

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
 tools/testing/selftests/kdbus/kdbus-enum.h |  1 +
 tools/testing/selftests/kdbus/kdbus-util.c |  2 +-
 tools/testing/selftests/kdbus/kdbus-util.h | 21 +++++++++------------
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/kdbus/kdbus-enum.h b/tools/testing/selftests/kdbus/kdbus-enum.h
index a67cec3512a7..ed28cca26906 100644
--- a/tools/testing/selftests/kdbus/kdbus-enum.h
+++ b/tools/testing/selftests/kdbus/kdbus-enum.h
@@ -6,6 +6,7 @@
  * Free Software Foundation; either version 2.1 of the License, or (at
  * your option) any later version.
  */
+
 #pragma once
 
 const char *enum_CMD(long long id);
diff --git a/tools/testing/selftests/kdbus/kdbus-util.c b/tools/testing/selftests/kdbus/kdbus-util.c
index 4b376ecfdbed..1e267d585a14 100644
--- a/tools/testing/selftests/kdbus/kdbus-util.c
+++ b/tools/testing/selftests/kdbus/kdbus-util.c
@@ -1353,7 +1353,7 @@ static int all_ids_are_mapped(const char *path)
 	return 0;
 }
 
-int all_uids_gids_are_mapped()
+int all_uids_gids_are_mapped(void)
 {
 	int ret;
 
diff --git a/tools/testing/selftests/kdbus/kdbus-util.h b/tools/testing/selftests/kdbus/kdbus-util.h
index 50ff07140bdd..b53b03f0565c 100644
--- a/tools/testing/selftests/kdbus/kdbus-util.h
+++ b/tools/testing/selftests/kdbus/kdbus-util.h
@@ -7,6 +7,7 @@
  * Free Software Foundation; either version 2.1 of the License, or (at
  * your option) any later version.
  */
+
 #pragma once
 
 #define BIT(X) (1 << (X))
@@ -30,24 +31,22 @@
 #define KDBUS_ITEM_FOREACH(item, head, first)				\
 	for (item = (head)->first;					\
 	     ((uint8_t *)(item) < (uint8_t *)(head) + (head)->size) &&	\
-	       ((uint8_t *)(item) >= (uint8_t *)(head));	\
+	       ((uint8_t *)(item) >= (uint8_t *)(head));		\
 	     item = KDBUS_ITEM_NEXT(item))
 #define KDBUS_FOREACH(iter, first, _size)				\
 	for (iter = (first);						\
 	     ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) &&	\
 	       ((uint8_t *)(iter) >= (uint8_t *)(first));		\
-	     iter = (void*)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
-
+	     iter = (void *)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
 
-#define _KDBUS_ATTACH_BITS_SET_NR  (__builtin_popcountll(_KDBUS_ATTACH_ALL))
+#define _KDBUS_ATTACH_BITS_SET_NR (__builtin_popcountll(_KDBUS_ATTACH_ALL))
 
 /* Sum of KDBUS_ITEM_* that reflects _KDBUS_ATTACH_ALL */
-#define KDBUS_ATTACH_ITEMS_TYPE_SUM \
-	((((_KDBUS_ATTACH_BITS_SET_NR - 1) * \
-	((_KDBUS_ATTACH_BITS_SET_NR - 1) + 1)) / 2 ) + \
+#define KDBUS_ATTACH_ITEMS_TYPE_SUM					\
+	((((_KDBUS_ATTACH_BITS_SET_NR - 1) *				\
+	((_KDBUS_ATTACH_BITS_SET_NR - 1) + 1)) / 2) +			\
 	(_KDBUS_ITEM_ATTACH_BASE * _KDBUS_ATTACH_BITS_SET_NR))
 
-
 #define POOL_SIZE (16 * 1024LU * 1024LU)
 
 #define UNPRIV_UID 65534
@@ -207,14 +206,12 @@ int kdbus_add_match_id(struct kdbus_conn *conn, uint64_t cookie,
 		       uint64_t type, uint64_t id);
 int kdbus_add_match_empty(struct kdbus_conn *conn);
 
-int all_uids_gids_are_mapped();
+int all_uids_gids_are_mapped(void);
 int drop_privileges(uid_t uid, gid_t gid);
 uint64_t now(clockid_t clock);
 char *unique_name(const char *prefix);
 
-int userns_map_uid_gid(pid_t pid,
-		       const char *map_uid,
-		       const char *map_gid);
+int userns_map_uid_gid(pid_t pid, const char *map_uid, const char *map_gid);
 int test_is_capable(int cap, ...);
 int config_user_ns_is_enabled(void);
 int config_auditsyscall_is_enabled(void);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 06/10] selftests/kdbus: fix precedence issues in macros
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
                   ` (4 preceding siblings ...)
  2015-06-09 21:00 ` [PATCH v2 05/10] selftests/kdbus: fix trivial style issues Sergei Zviagintsev
@ 2015-06-09 21:00 ` Sergei Zviagintsev
  2015-06-10 14:06   ` David Herrmann
  2015-06-09 21:00 ` [PATCH v2 07/10] selftests/kdbus: use parentheses in iteration macros uniformly Sergei Zviagintsev
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-09 21:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni
  Cc: linux-kernel, Sergei Zviagintsev

`item' argument in KDBUS_ITEM_NEXT macro is not enclosed into
parentheses when the cast operator is applied, which leads to improper
type conversion if `item' is supplied as a complex expression, e.g.

    KDBUS_ITEM_NEXT(condition ? a : b)

RUN_CLONE_CHILD macro has similar issue, missing parentheses around
`clone_ret' when using indirection operator.

Use parentheses properly to guarantee right precedence.

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
 tools/testing/selftests/kdbus/kdbus-util.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/kdbus/kdbus-util.h b/tools/testing/selftests/kdbus/kdbus-util.h
index b53b03f0565c..df5721ee8f54 100644
--- a/tools/testing/selftests/kdbus/kdbus-util.h
+++ b/tools/testing/selftests/kdbus/kdbus-util.h
@@ -27,7 +27,7 @@
 #define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE)
 
 #define KDBUS_ITEM_NEXT(item) \
-	(typeof(item))(((uint8_t *)item) + KDBUS_ALIGN8((item)->size))
+	(typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))
 #define KDBUS_ITEM_FOREACH(item, head, first)				\
 	for (item = (head)->first;					\
 	     ((uint8_t *)(item) < (uint8_t *)(head) + (head)->size) &&	\
@@ -104,7 +104,7 @@ extern int kdbus_util_verbose;
 	_setup_;							\
 	efd = eventfd(0, EFD_CLOEXEC);					\
 	ASSERT_RETURN(efd >= 0);					\
-	*clone_ret = 0;							\
+	*(clone_ret) = 0;						\
 	pid = syscall(__NR_clone, flags, NULL);				\
 	if (pid == 0) {							\
 		eventfd_t event_status = 0;				\
@@ -129,7 +129,7 @@ extern int kdbus_util_verbose;
 		ret = TEST_OK;						\
 	} else {							\
 		ret = -errno;						\
-		*clone_ret = -errno;					\
+		*(clone_ret) = -errno;					\
 	}								\
 	close(efd);							\
 	ret;								\
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 07/10] selftests/kdbus: use parentheses in iteration macros uniformly
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
                   ` (5 preceding siblings ...)
  2015-06-09 21:00 ` [PATCH v2 06/10] selftests/kdbus: fix precedence issues in macros Sergei Zviagintsev
@ 2015-06-09 21:00 ` Sergei Zviagintsev
  2015-06-10 14:08   ` David Herrmann
  2015-06-09 21:00 ` [PATCH v2 08/10] samples/kdbus: add whitespace Sergei Zviagintsev
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-09 21:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni
  Cc: linux-kernel, Sergei Zviagintsev

Enclose all arguments into parentheses in KDBUS_ITEM_FOREACH and
KDBUS_FOREACH macros to stay consistent across the whole macro.

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
 tools/testing/selftests/kdbus/kdbus-util.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/kdbus/kdbus-util.h b/tools/testing/selftests/kdbus/kdbus-util.h
index df5721ee8f54..d1a0f1b4d0eb 100644
--- a/tools/testing/selftests/kdbus/kdbus-util.h
+++ b/tools/testing/selftests/kdbus/kdbus-util.h
@@ -29,15 +29,15 @@
 #define KDBUS_ITEM_NEXT(item) \
 	(typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))
 #define KDBUS_ITEM_FOREACH(item, head, first)				\
-	for (item = (head)->first;					\
+	for ((item) = (head)->first;					\
 	     ((uint8_t *)(item) < (uint8_t *)(head) + (head)->size) &&	\
 	       ((uint8_t *)(item) >= (uint8_t *)(head));		\
-	     item = KDBUS_ITEM_NEXT(item))
+	     (item) = KDBUS_ITEM_NEXT(item))
 #define KDBUS_FOREACH(iter, first, _size)				\
-	for (iter = (first);						\
+	for ((iter) = (first);						\
 	     ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) &&	\
 	       ((uint8_t *)(iter) >= (uint8_t *)(first));		\
-	     iter = (void *)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
+	     (iter) = (void *)((uint8_t *)(iter) + KDBUS_ALIGN8((iter)->size)))
 
 #define _KDBUS_ATTACH_BITS_SET_NR (__builtin_popcountll(_KDBUS_ATTACH_ALL))
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 08/10] samples/kdbus: add whitespace
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
                   ` (6 preceding siblings ...)
  2015-06-09 21:00 ` [PATCH v2 07/10] selftests/kdbus: use parentheses in iteration macros uniformly Sergei Zviagintsev
@ 2015-06-09 21:00 ` Sergei Zviagintsev
  2015-06-10 14:09   ` David Herrmann
  2015-06-09 21:00 ` [PATCH v2 09/10] samples/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro Sergei Zviagintsev
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-09 21:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni
  Cc: linux-kernel, Sergei Zviagintsev

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
 samples/kdbus/kdbus-api.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/samples/kdbus/kdbus-api.h b/samples/kdbus/kdbus-api.h
index 5ed5907c5cb4..2de4d6a8c51e 100644
--- a/samples/kdbus/kdbus-api.h
+++ b/samples/kdbus/kdbus-api.h
@@ -13,7 +13,7 @@
 	for (iter = (first);						\
 	     ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) &&	\
 	       ((uint8_t *)(iter) >= (uint8_t *)(first));		\
-	     iter = (void*)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
+	     iter = (void *)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
 
 static inline int kdbus_cmd_bus_make(int control_fd, struct kdbus_cmd *cmd)
 {
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 09/10] samples/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
                   ` (7 preceding siblings ...)
  2015-06-09 21:00 ` [PATCH v2 08/10] samples/kdbus: add whitespace Sergei Zviagintsev
@ 2015-06-09 21:00 ` Sergei Zviagintsev
  2015-06-10 14:09   ` David Herrmann
  2015-06-09 21:00 ` [PATCH v2 10/10] samples/kdbus: use parentheses uniformly in KDBUS_FOREACH macro Sergei Zviagintsev
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-09 21:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni
  Cc: linux-kernel, Sergei Zviagintsev

`item' argument in KDBUS_ITEM_NEXT macro is not enclosed into
parentheses when the cast operator is applied, which leads to improper
type conversion if `item' is supplied as a complex expression, e.g.

    KDBUS_ITEM_NEXT(condition ? a : b)

Use parentheses properly to guarantee right precedence.

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
 samples/kdbus/kdbus-api.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/samples/kdbus/kdbus-api.h b/samples/kdbus/kdbus-api.h
index 2de4d6a8c51e..fab873b89d97 100644
--- a/samples/kdbus/kdbus-api.h
+++ b/samples/kdbus/kdbus-api.h
@@ -8,7 +8,7 @@
 #define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
 #define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE)
 #define KDBUS_ITEM_NEXT(item) \
-	(typeof(item))(((uint8_t *)item) + KDBUS_ALIGN8((item)->size))
+	(typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))
 #define KDBUS_FOREACH(iter, first, _size)				\
 	for (iter = (first);						\
 	     ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) &&	\
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 10/10] samples/kdbus: use parentheses uniformly in KDBUS_FOREACH macro
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
                   ` (8 preceding siblings ...)
  2015-06-09 21:00 ` [PATCH v2 09/10] samples/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro Sergei Zviagintsev
@ 2015-06-09 21:00 ` Sergei Zviagintsev
  2015-06-10 14:10   ` David Herrmann
  2015-06-10 14:13 ` [PATCH v2 00/10] kdbus: macros fixes David Herrmann
  2015-06-19  5:05 ` Greg Kroah-Hartman
  11 siblings, 1 reply; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-09 21:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni
  Cc: linux-kernel, Sergei Zviagintsev

Enclose all arguments into parentheses to stay consistent across the
whole macro.

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
 samples/kdbus/kdbus-api.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/samples/kdbus/kdbus-api.h b/samples/kdbus/kdbus-api.h
index fab873b89d97..7f3abae18396 100644
--- a/samples/kdbus/kdbus-api.h
+++ b/samples/kdbus/kdbus-api.h
@@ -10,10 +10,10 @@
 #define KDBUS_ITEM_NEXT(item) \
 	(typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))
 #define KDBUS_FOREACH(iter, first, _size)				\
-	for (iter = (first);						\
+	for ((iter) = (first);						\
 	     ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) &&	\
 	       ((uint8_t *)(iter) >= (uint8_t *)(first));		\
-	     iter = (void *)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
+	     (iter) = (void *)((uint8_t *)(iter) + KDBUS_ALIGN8((iter)->size)))
 
 static inline int kdbus_cmd_bus_make(int control_fd, struct kdbus_cmd *cmd)
 {
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 01/10] kdbus: fix operator precedence issues in item macros
  2015-06-09 20:59 ` [PATCH v2 01/10] kdbus: fix operator precedence issues in item macros Sergei Zviagintsev
@ 2015-06-10 13:44   ` David Herrmann
  0 siblings, 0 replies; 24+ messages in thread
From: David Herrmann @ 2015-06-10 13:44 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Tue, Jun 9, 2015 at 10:59 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> `_i' argument in KDBUS_ITEM_NEXT and KDBUS_ITEMS_END macros is not
> enclosed into parentheses when the cast operator is applied, which
> leads to improper type conversion if `_i' is supplied as a complex
> expression, e.g.
>
>     KDBUS_ITEM_NEXT(condition ? a : b)
>
> KDBUS_ITEMS_SIZE macro has similar issue, missing parentheses around
> `_h' when using indirection operator.
>
> Use parentheses properly to guarantee right precedence.
>
> Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
> ---
>  ipc/kdbus/item.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> diff --git a/ipc/kdbus/item.h b/ipc/kdbus/item.h
> index eeefd8beac3b..32909e2e7954 100644
> --- a/ipc/kdbus/item.h
> +++ b/ipc/kdbus/item.h
> @@ -21,8 +21,8 @@
>  #include "util.h"
>
>  /* generic access and iterators over a stream of items */
> -#define KDBUS_ITEM_NEXT(_i) (typeof(_i))(((u8 *)_i) + KDBUS_ALIGN8((_i)->size))
> -#define KDBUS_ITEMS_SIZE(_h, _is) ((_h)->size - offsetof(typeof(*_h), _is))
> +#define KDBUS_ITEM_NEXT(_i) (typeof(_i))((u8 *)(_i) + KDBUS_ALIGN8((_i)->size))
> +#define KDBUS_ITEMS_SIZE(_h, _is) ((_h)->size - offsetof(typeof(*(_h)), _is))
>  #define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
>  #define KDBUS_ITEM_SIZE(_s) KDBUS_ALIGN8(KDBUS_ITEM_HEADER_SIZE + (_s))
>  #define KDBUS_ITEM_PAYLOAD_SIZE(_i) ((_i)->size - KDBUS_ITEM_HEADER_SIZE)
> @@ -40,7 +40,7 @@
>          (u8 *)(_i) >= (u8 *)(_is))
>
>  #define KDBUS_ITEMS_END(_i, _is, _s)                                   \
> -       ((u8 *)_i == ((u8 *)(_is) + KDBUS_ALIGN8(_s)))
> +       ((u8 *)(_i) == ((u8 *)(_is) + KDBUS_ALIGN8(_s)))
>
>  /**
>   * struct kdbus_item_header - Describes the fix part of an item
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 02/10] kdbus: use parentheses uniformly in KDBUS_ITEMS_FOREACH macro
  2015-06-09 21:00 ` [PATCH v2 02/10] kdbus: use parentheses uniformly in KDBUS_ITEMS_FOREACH macro Sergei Zviagintsev
@ 2015-06-10 13:46   ` David Herrmann
  0 siblings, 0 replies; 24+ messages in thread
From: David Herrmann @ 2015-06-10 13:46 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Tue, Jun 9, 2015 at 11:00 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> Enclose all arguments into parentheses to stay consistent across the
> whole macro.
>
> Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
> ---
>  ipc/kdbus/item.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> diff --git a/ipc/kdbus/item.h b/ipc/kdbus/item.h
> index 32909e2e7954..bca63b4e6e80 100644
> --- a/ipc/kdbus/item.h
> +++ b/ipc/kdbus/item.h
> @@ -28,10 +28,10 @@
>  #define KDBUS_ITEM_PAYLOAD_SIZE(_i) ((_i)->size - KDBUS_ITEM_HEADER_SIZE)
>
>  #define KDBUS_ITEMS_FOREACH(_i, _is, _s)                               \
> -       for (_i = _is;                                                  \
> +       for ((_i) = (_is);                                              \
>              ((u8 *)(_i) < (u8 *)(_is) + (_s)) &&                       \
>                ((u8 *)(_i) >= (u8 *)(_is));                             \
> -            _i = KDBUS_ITEM_NEXT(_i))
> +            (_i) = KDBUS_ITEM_NEXT(_i))
>
>  #define KDBUS_ITEM_VALID(_i, _is, _s)                                  \
>         ((_i)->size >= KDBUS_ITEM_HEADER_SIZE &&                        \
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 03/10] Documentation/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro
  2015-06-09 21:00 ` [PATCH v2 03/10] Documentation/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro Sergei Zviagintsev
@ 2015-06-10 14:03   ` David Herrmann
  0 siblings, 0 replies; 24+ messages in thread
From: David Herrmann @ 2015-06-10 14:03 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Tue, Jun 9, 2015 at 11:00 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> `item' argument in KDBUS_ITEM_NEXT macro example is not enclosed into
> parentheses when the cast operator is applied, which leads to improper
> type conversion if `item' is supplied as a complex expression, e.g.
>
>     KDBUS_ITEM_NEXT(condition ? a : b)
>
> Use parentheses properly to guarantee right precedence.
>
> Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
> ---
>  Documentation/kdbus/kdbus.item.xml | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> diff --git a/Documentation/kdbus/kdbus.item.xml b/Documentation/kdbus/kdbus.item.xml
> index 09f8b903116f..b0eeeef995af 100644
> --- a/Documentation/kdbus/kdbus.item.xml
> +++ b/Documentation/kdbus/kdbus.item.xml
> @@ -69,7 +69,7 @@
>  #define KDBUS_ALIGN8(val) (((val) + 7) & ~7)
>
>  #define KDBUS_ITEM_NEXT(item) \
> -    (typeof(item))(((uint8_t *)item) + KDBUS_ALIGN8((item)->size))
> +    (typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))
>
>  #define KDBUS_ITEM_FOREACH(item, head, first)                      \
>      for (item = (head)->first;                                     \
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 04/10] Documentation/kdbus: use parentheses uniformly in KDBUS_ITEM_FOREACH macro
  2015-06-09 21:00 ` [PATCH v2 04/10] Documentation/kdbus: use parentheses uniformly in KDBUS_ITEM_FOREACH macro Sergei Zviagintsev
@ 2015-06-10 14:03   ` David Herrmann
  0 siblings, 0 replies; 24+ messages in thread
From: David Herrmann @ 2015-06-10 14:03 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Tue, Jun 9, 2015 at 11:00 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> Enclose all arguments into parentheses to stay consistent across the
> whole macro.
>
> Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
> ---
>  Documentation/kdbus/kdbus.item.xml | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/kdbus/kdbus.item.xml b/Documentation/kdbus/kdbus.item.xml
> index b0eeeef995af..ee09dfa443b8 100644
> --- a/Documentation/kdbus/kdbus.item.xml
> +++ b/Documentation/kdbus/kdbus.item.xml
> @@ -72,10 +72,10 @@
>      (typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

>  #define KDBUS_ITEM_FOREACH(item, head, first)                      \
> -    for (item = (head)->first;                                     \
> +    for ((item) = (head)->first;                                   \
>           ((uint8_t *)(item) < (uint8_t *)(head) + (head)->size) && \
>            ((uint8_t *)(item) >= (uint8_t *)(head));                \
> -         item = KDBUS_ITEM_NEXT(item))
> +         (item) = KDBUS_ITEM_NEXT(item))
>        ]]></programlisting>
>      </refsect2>
>    </refsect1>
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 05/10] selftests/kdbus: fix trivial style issues
  2015-06-09 21:00 ` [PATCH v2 05/10] selftests/kdbus: fix trivial style issues Sergei Zviagintsev
@ 2015-06-10 14:05   ` David Herrmann
  0 siblings, 0 replies; 24+ messages in thread
From: David Herrmann @ 2015-06-10 14:05 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Tue, Jun 9, 2015 at 11:00 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
> ---
>  tools/testing/selftests/kdbus/kdbus-enum.h |  1 +
>  tools/testing/selftests/kdbus/kdbus-util.c |  2 +-
>  tools/testing/selftests/kdbus/kdbus-util.h | 21 +++++++++------------
>  3 files changed, 11 insertions(+), 13 deletions(-)

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> diff --git a/tools/testing/selftests/kdbus/kdbus-enum.h b/tools/testing/selftests/kdbus/kdbus-enum.h
> index a67cec3512a7..ed28cca26906 100644
> --- a/tools/testing/selftests/kdbus/kdbus-enum.h
> +++ b/tools/testing/selftests/kdbus/kdbus-enum.h
> @@ -6,6 +6,7 @@
>   * Free Software Foundation; either version 2.1 of the License, or (at
>   * your option) any later version.
>   */
> +
>  #pragma once
>
>  const char *enum_CMD(long long id);
> diff --git a/tools/testing/selftests/kdbus/kdbus-util.c b/tools/testing/selftests/kdbus/kdbus-util.c
> index 4b376ecfdbed..1e267d585a14 100644
> --- a/tools/testing/selftests/kdbus/kdbus-util.c
> +++ b/tools/testing/selftests/kdbus/kdbus-util.c
> @@ -1353,7 +1353,7 @@ static int all_ids_are_mapped(const char *path)
>         return 0;
>  }
>
> -int all_uids_gids_are_mapped()
> +int all_uids_gids_are_mapped(void)
>  {
>         int ret;
>
> diff --git a/tools/testing/selftests/kdbus/kdbus-util.h b/tools/testing/selftests/kdbus/kdbus-util.h
> index 50ff07140bdd..b53b03f0565c 100644
> --- a/tools/testing/selftests/kdbus/kdbus-util.h
> +++ b/tools/testing/selftests/kdbus/kdbus-util.h
> @@ -7,6 +7,7 @@
>   * Free Software Foundation; either version 2.1 of the License, or (at
>   * your option) any later version.
>   */
> +
>  #pragma once
>
>  #define BIT(X) (1 << (X))
> @@ -30,24 +31,22 @@
>  #define KDBUS_ITEM_FOREACH(item, head, first)                          \
>         for (item = (head)->first;                                      \
>              ((uint8_t *)(item) < (uint8_t *)(head) + (head)->size) &&  \
> -              ((uint8_t *)(item) >= (uint8_t *)(head));        \
> +              ((uint8_t *)(item) >= (uint8_t *)(head));                \
>              item = KDBUS_ITEM_NEXT(item))
>  #define KDBUS_FOREACH(iter, first, _size)                              \
>         for (iter = (first);                                            \
>              ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) &&      \
>                ((uint8_t *)(iter) >= (uint8_t *)(first));               \
> -            iter = (void*)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
> -
> +            iter = (void *)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
>
> -#define _KDBUS_ATTACH_BITS_SET_NR  (__builtin_popcountll(_KDBUS_ATTACH_ALL))
> +#define _KDBUS_ATTACH_BITS_SET_NR (__builtin_popcountll(_KDBUS_ATTACH_ALL))
>
>  /* Sum of KDBUS_ITEM_* that reflects _KDBUS_ATTACH_ALL */
> -#define KDBUS_ATTACH_ITEMS_TYPE_SUM \
> -       ((((_KDBUS_ATTACH_BITS_SET_NR - 1) * \
> -       ((_KDBUS_ATTACH_BITS_SET_NR - 1) + 1)) / 2 ) + \
> +#define KDBUS_ATTACH_ITEMS_TYPE_SUM                                    \
> +       ((((_KDBUS_ATTACH_BITS_SET_NR - 1) *                            \
> +       ((_KDBUS_ATTACH_BITS_SET_NR - 1) + 1)) / 2) +                   \
>         (_KDBUS_ITEM_ATTACH_BASE * _KDBUS_ATTACH_BITS_SET_NR))
>
> -
>  #define POOL_SIZE (16 * 1024LU * 1024LU)
>
>  #define UNPRIV_UID 65534
> @@ -207,14 +206,12 @@ int kdbus_add_match_id(struct kdbus_conn *conn, uint64_t cookie,
>                        uint64_t type, uint64_t id);
>  int kdbus_add_match_empty(struct kdbus_conn *conn);
>
> -int all_uids_gids_are_mapped();
> +int all_uids_gids_are_mapped(void);
>  int drop_privileges(uid_t uid, gid_t gid);
>  uint64_t now(clockid_t clock);
>  char *unique_name(const char *prefix);
>
> -int userns_map_uid_gid(pid_t pid,
> -                      const char *map_uid,
> -                      const char *map_gid);
> +int userns_map_uid_gid(pid_t pid, const char *map_uid, const char *map_gid);
>  int test_is_capable(int cap, ...);
>  int config_user_ns_is_enabled(void);
>  int config_auditsyscall_is_enabled(void);
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 06/10] selftests/kdbus: fix precedence issues in macros
  2015-06-09 21:00 ` [PATCH v2 06/10] selftests/kdbus: fix precedence issues in macros Sergei Zviagintsev
@ 2015-06-10 14:06   ` David Herrmann
  0 siblings, 0 replies; 24+ messages in thread
From: David Herrmann @ 2015-06-10 14:06 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Tue, Jun 9, 2015 at 11:00 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> `item' argument in KDBUS_ITEM_NEXT macro is not enclosed into
> parentheses when the cast operator is applied, which leads to improper
> type conversion if `item' is supplied as a complex expression, e.g.
>
>     KDBUS_ITEM_NEXT(condition ? a : b)
>
> RUN_CLONE_CHILD macro has similar issue, missing parentheses around
> `clone_ret' when using indirection operator.
>
> Use parentheses properly to guarantee right precedence.
>
> Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
> ---
>  tools/testing/selftests/kdbus/kdbus-util.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> diff --git a/tools/testing/selftests/kdbus/kdbus-util.h b/tools/testing/selftests/kdbus/kdbus-util.h
> index b53b03f0565c..df5721ee8f54 100644
> --- a/tools/testing/selftests/kdbus/kdbus-util.h
> +++ b/tools/testing/selftests/kdbus/kdbus-util.h
> @@ -27,7 +27,7 @@
>  #define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE)
>
>  #define KDBUS_ITEM_NEXT(item) \
> -       (typeof(item))(((uint8_t *)item) + KDBUS_ALIGN8((item)->size))
> +       (typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))
>  #define KDBUS_ITEM_FOREACH(item, head, first)                          \
>         for (item = (head)->first;                                      \
>              ((uint8_t *)(item) < (uint8_t *)(head) + (head)->size) &&  \
> @@ -104,7 +104,7 @@ extern int kdbus_util_verbose;
>         _setup_;                                                        \
>         efd = eventfd(0, EFD_CLOEXEC);                                  \
>         ASSERT_RETURN(efd >= 0);                                        \
> -       *clone_ret = 0;                                                 \
> +       *(clone_ret) = 0;                                               \
>         pid = syscall(__NR_clone, flags, NULL);                         \
>         if (pid == 0) {                                                 \
>                 eventfd_t event_status = 0;                             \
> @@ -129,7 +129,7 @@ extern int kdbus_util_verbose;
>                 ret = TEST_OK;                                          \
>         } else {                                                        \
>                 ret = -errno;                                           \
> -               *clone_ret = -errno;                                    \
> +               *(clone_ret) = -errno;                                  \
>         }                                                               \
>         close(efd);                                                     \
>         ret;                                                            \
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 07/10] selftests/kdbus: use parentheses in iteration macros uniformly
  2015-06-09 21:00 ` [PATCH v2 07/10] selftests/kdbus: use parentheses in iteration macros uniformly Sergei Zviagintsev
@ 2015-06-10 14:08   ` David Herrmann
  0 siblings, 0 replies; 24+ messages in thread
From: David Herrmann @ 2015-06-10 14:08 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Tue, Jun 9, 2015 at 11:00 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> Enclose all arguments into parentheses in KDBUS_ITEM_FOREACH and
> KDBUS_FOREACH macros to stay consistent across the whole macro.
>
> Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
> ---
>  tools/testing/selftests/kdbus/kdbus-util.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> diff --git a/tools/testing/selftests/kdbus/kdbus-util.h b/tools/testing/selftests/kdbus/kdbus-util.h
> index df5721ee8f54..d1a0f1b4d0eb 100644
> --- a/tools/testing/selftests/kdbus/kdbus-util.h
> +++ b/tools/testing/selftests/kdbus/kdbus-util.h
> @@ -29,15 +29,15 @@
>  #define KDBUS_ITEM_NEXT(item) \
>         (typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))
>  #define KDBUS_ITEM_FOREACH(item, head, first)                          \
> -       for (item = (head)->first;                                      \
> +       for ((item) = (head)->first;                                    \
>              ((uint8_t *)(item) < (uint8_t *)(head) + (head)->size) &&  \
>                ((uint8_t *)(item) >= (uint8_t *)(head));                \
> -            item = KDBUS_ITEM_NEXT(item))
> +            (item) = KDBUS_ITEM_NEXT(item))
>  #define KDBUS_FOREACH(iter, first, _size)                              \
> -       for (iter = (first);                                            \
> +       for ((iter) = (first);                                          \
>              ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) &&      \
>                ((uint8_t *)(iter) >= (uint8_t *)(first));               \
> -            iter = (void *)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
> +            (iter) = (void *)((uint8_t *)(iter) + KDBUS_ALIGN8((iter)->size)))
>
>  #define _KDBUS_ATTACH_BITS_SET_NR (__builtin_popcountll(_KDBUS_ATTACH_ALL))
>
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 08/10] samples/kdbus: add whitespace
  2015-06-09 21:00 ` [PATCH v2 08/10] samples/kdbus: add whitespace Sergei Zviagintsev
@ 2015-06-10 14:09   ` David Herrmann
  0 siblings, 0 replies; 24+ messages in thread
From: David Herrmann @ 2015-06-10 14:09 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Tue, Jun 9, 2015 at 11:00 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
> ---
>  samples/kdbus/kdbus-api.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> diff --git a/samples/kdbus/kdbus-api.h b/samples/kdbus/kdbus-api.h
> index 5ed5907c5cb4..2de4d6a8c51e 100644
> --- a/samples/kdbus/kdbus-api.h
> +++ b/samples/kdbus/kdbus-api.h
> @@ -13,7 +13,7 @@
>         for (iter = (first);                                            \
>              ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) &&      \
>                ((uint8_t *)(iter) >= (uint8_t *)(first));               \
> -            iter = (void*)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
> +            iter = (void *)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
>
>  static inline int kdbus_cmd_bus_make(int control_fd, struct kdbus_cmd *cmd)
>  {
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 09/10] samples/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro
  2015-06-09 21:00 ` [PATCH v2 09/10] samples/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro Sergei Zviagintsev
@ 2015-06-10 14:09   ` David Herrmann
  0 siblings, 0 replies; 24+ messages in thread
From: David Herrmann @ 2015-06-10 14:09 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Tue, Jun 9, 2015 at 11:00 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> `item' argument in KDBUS_ITEM_NEXT macro is not enclosed into
> parentheses when the cast operator is applied, which leads to improper
> type conversion if `item' is supplied as a complex expression, e.g.
>
>     KDBUS_ITEM_NEXT(condition ? a : b)
>
> Use parentheses properly to guarantee right precedence.
>
> Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
> ---
>  samples/kdbus/kdbus-api.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> diff --git a/samples/kdbus/kdbus-api.h b/samples/kdbus/kdbus-api.h
> index 2de4d6a8c51e..fab873b89d97 100644
> --- a/samples/kdbus/kdbus-api.h
> +++ b/samples/kdbus/kdbus-api.h
> @@ -8,7 +8,7 @@
>  #define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
>  #define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE)
>  #define KDBUS_ITEM_NEXT(item) \
> -       (typeof(item))(((uint8_t *)item) + KDBUS_ALIGN8((item)->size))
> +       (typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))
>  #define KDBUS_FOREACH(iter, first, _size)                              \
>         for (iter = (first);                                            \
>              ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) &&      \
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 10/10] samples/kdbus: use parentheses uniformly in KDBUS_FOREACH macro
  2015-06-09 21:00 ` [PATCH v2 10/10] samples/kdbus: use parentheses uniformly in KDBUS_FOREACH macro Sergei Zviagintsev
@ 2015-06-10 14:10   ` David Herrmann
  0 siblings, 0 replies; 24+ messages in thread
From: David Herrmann @ 2015-06-10 14:10 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Tue, Jun 9, 2015 at 11:00 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> Enclose all arguments into parentheses to stay consistent across the
> whole macro.
>
> Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
> ---
>  samples/kdbus/kdbus-api.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> diff --git a/samples/kdbus/kdbus-api.h b/samples/kdbus/kdbus-api.h
> index fab873b89d97..7f3abae18396 100644
> --- a/samples/kdbus/kdbus-api.h
> +++ b/samples/kdbus/kdbus-api.h
> @@ -10,10 +10,10 @@
>  #define KDBUS_ITEM_NEXT(item) \
>         (typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size))
>  #define KDBUS_FOREACH(iter, first, _size)                              \
> -       for (iter = (first);                                            \
> +       for ((iter) = (first);                                          \
>              ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) &&      \
>                ((uint8_t *)(iter) >= (uint8_t *)(first));               \
> -            iter = (void *)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size)))
> +            (iter) = (void *)((uint8_t *)(iter) + KDBUS_ALIGN8((iter)->size)))
>
>  static inline int kdbus_cmd_bus_make(int control_fd, struct kdbus_cmd *cmd)
>  {
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 00/10] kdbus: macros fixes
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
                   ` (9 preceding siblings ...)
  2015-06-09 21:00 ` [PATCH v2 10/10] samples/kdbus: use parentheses uniformly in KDBUS_FOREACH macro Sergei Zviagintsev
@ 2015-06-10 14:13 ` David Herrmann
  2015-06-10 14:56   ` Sergei Zviagintsev
  2015-06-19  5:05 ` Greg Kroah-Hartman
  11 siblings, 1 reply; 24+ messages in thread
From: David Herrmann @ 2015-06-10 14:13 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Tue, Jun 9, 2015 at 10:59 PM, Sergei Zviagintsev <sergei@s15v.net> wrote:
> Fix type conversion and style issues in item macros.
>
> First submission was in 2 separate emails:
> https://lkml.kernel.org/g/1433414370-17557-1-git-send-email-sergei@s15v.net
> https://lkml.kernel.org/g/1433414370-17557-2-git-send-email-sergei@s15v.net
>
> Changes in v2:
>
>  - fixed similar type cast issue in KDBUS_ITEMS_END macro
>  - all arguments in iteration macros are enclosed in parentheses,
>    instead of using loop cursor without them
>  - summary phrases and commit messages updated
>  - documentation updates are excluded to their own patches
>  - added fixes for samples/kdbus
>  - added fixes for selftests/kdbus
>
>
> Sergei Zviagintsev (10):
>   kdbus: fix operator precedence issues in item macros
>   kdbus: use parentheses uniformly in KDBUS_ITEMS_FOREACH macro
>   Documentation/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT
>     macro
>   Documentation/kdbus: use parentheses uniformly in KDBUS_ITEM_FOREACH
>     macro
>   selftests/kdbus: fix trivial style issues
>   selftests/kdbus: fix precedence issues in macros
>   selftests/kdbus: use parentheses in iteration macros uniformly
>   samples/kdbus: add whitespace
>   samples/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro
>   samples/kdbus: use parentheses uniformly in KDBUS_FOREACH macro

Next time, please merge most of these changes to reduce the number of
patches and review-overhead. But looks all good to me, much
appreciated.

Thanks
David

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 00/10] kdbus: macros fixes
  2015-06-10 14:13 ` [PATCH v2 00/10] kdbus: macros fixes David Herrmann
@ 2015-06-10 14:56   ` Sergei Zviagintsev
  0 siblings, 0 replies; 24+ messages in thread
From: Sergei Zviagintsev @ 2015-06-10 14:56 UTC (permalink / raw)
  To: David Herrmann
  Cc: Greg Kroah-Hartman, Daniel Mack, David Herrmann, Djalal Harouni,
	linux-kernel

Hi

On Wed, Jun 10, 2015 at 04:13:49PM +0200, David Herrmann wrote:
> Next time, please merge most of these changes to reduce the number of
> patches and review-overhead. But looks all good to me, much
> appreciated.

Thank you for response, I will keep that in mind.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 00/10] kdbus: macros fixes
  2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
                   ` (10 preceding siblings ...)
  2015-06-10 14:13 ` [PATCH v2 00/10] kdbus: macros fixes David Herrmann
@ 2015-06-19  5:05 ` Greg Kroah-Hartman
  11 siblings, 0 replies; 24+ messages in thread
From: Greg Kroah-Hartman @ 2015-06-19  5:05 UTC (permalink / raw)
  To: Sergei Zviagintsev
  Cc: Daniel Mack, David Herrmann, Djalal Harouni, linux-kernel

On Tue, Jun 09, 2015 at 11:59:58PM +0300, Sergei Zviagintsev wrote:
> Fix type conversion and style issues in item macros.
> 
> First submission was in 2 separate emails:
> https://lkml.kernel.org/g/1433414370-17557-1-git-send-email-sergei@s15v.net
> https://lkml.kernel.org/g/1433414370-17557-2-git-send-email-sergei@s15v.net
> 
> Changes in v2:
> 
>  - fixed similar type cast issue in KDBUS_ITEMS_END macro
>  - all arguments in iteration macros are enclosed in parentheses,
>    instead of using loop cursor without them
>  - summary phrases and commit messages updated
>  - documentation updates are excluded to their own patches
>  - added fixes for samples/kdbus
>  - added fixes for selftests/kdbus
> 
> 
> Sergei Zviagintsev (10):
>   kdbus: fix operator precedence issues in item macros
>   kdbus: use parentheses uniformly in KDBUS_ITEMS_FOREACH macro
>   Documentation/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT
>     macro
>   Documentation/kdbus: use parentheses uniformly in KDBUS_ITEM_FOREACH
>     macro
>   selftests/kdbus: fix trivial style issues
>   selftests/kdbus: fix precedence issues in macros
>   selftests/kdbus: use parentheses in iteration macros uniformly
>   samples/kdbus: add whitespace
>   samples/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro
>   samples/kdbus: use parentheses uniformly in KDBUS_FOREACH macro
> 
>  Documentation/kdbus/kdbus.item.xml         |  6 +++---
>  ipc/kdbus/item.h                           | 10 ++++-----
>  samples/kdbus/kdbus-api.h                  |  6 +++---
>  tools/testing/selftests/kdbus/kdbus-enum.h |  1 +
>  tools/testing/selftests/kdbus/kdbus-util.c |  2 +-
>  tools/testing/selftests/kdbus/kdbus-util.h | 33 ++++++++++++++----------------
>  6 files changed, 28 insertions(+), 30 deletions(-)

All now applied, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2015-06-19  5:05 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-09 20:59 [PATCH v2 00/10] kdbus: macros fixes Sergei Zviagintsev
2015-06-09 20:59 ` [PATCH v2 01/10] kdbus: fix operator precedence issues in item macros Sergei Zviagintsev
2015-06-10 13:44   ` David Herrmann
2015-06-09 21:00 ` [PATCH v2 02/10] kdbus: use parentheses uniformly in KDBUS_ITEMS_FOREACH macro Sergei Zviagintsev
2015-06-10 13:46   ` David Herrmann
2015-06-09 21:00 ` [PATCH v2 03/10] Documentation/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro Sergei Zviagintsev
2015-06-10 14:03   ` David Herrmann
2015-06-09 21:00 ` [PATCH v2 04/10] Documentation/kdbus: use parentheses uniformly in KDBUS_ITEM_FOREACH macro Sergei Zviagintsev
2015-06-10 14:03   ` David Herrmann
2015-06-09 21:00 ` [PATCH v2 05/10] selftests/kdbus: fix trivial style issues Sergei Zviagintsev
2015-06-10 14:05   ` David Herrmann
2015-06-09 21:00 ` [PATCH v2 06/10] selftests/kdbus: fix precedence issues in macros Sergei Zviagintsev
2015-06-10 14:06   ` David Herrmann
2015-06-09 21:00 ` [PATCH v2 07/10] selftests/kdbus: use parentheses in iteration macros uniformly Sergei Zviagintsev
2015-06-10 14:08   ` David Herrmann
2015-06-09 21:00 ` [PATCH v2 08/10] samples/kdbus: add whitespace Sergei Zviagintsev
2015-06-10 14:09   ` David Herrmann
2015-06-09 21:00 ` [PATCH v2 09/10] samples/kdbus: fix operator precedence issue in KDBUS_ITEM_NEXT macro Sergei Zviagintsev
2015-06-10 14:09   ` David Herrmann
2015-06-09 21:00 ` [PATCH v2 10/10] samples/kdbus: use parentheses uniformly in KDBUS_FOREACH macro Sergei Zviagintsev
2015-06-10 14:10   ` David Herrmann
2015-06-10 14:13 ` [PATCH v2 00/10] kdbus: macros fixes David Herrmann
2015-06-10 14:56   ` Sergei Zviagintsev
2015-06-19  5:05 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).