Re: [PATCH net-next 3/6] genetlink: add helper for checking required attrs and use it in devlink
From: Johannes Berg <johannes@sipsolutions.net>
Date: 2022-08-24 19:44:34
From: Johannes Berg <johannes@sipsolutions.net>
Date: 2022-08-24 19:44:34
On Tue, 2022-08-23 at 21:50 -0700, Jakub Kicinski wrote:
+/* Report that a root attribute is missing */
+#define GENL_REQ_ATTR_CHECK(info, attr) ({ \
+ struct genl_info *__info = (info); \
+ u32 __attr = (attr); \
+ int __retval; \
+ \
+ __retval = !__info->attrs[__attr]; \
+ if (__retval) \
+ NL_SET_ERR_ATTR_MISS(__info->extack, \
+ __info->userhdr ? : __info->genlhdr, \
+ __attr); \
+ __retval; \
+})Not sure this needs to be a macro btw, could be an inline returning a bool? You're not really expanding anything here, nor doing something with strings (unlike GENL_SET_ERR_MSG for example.) johannes