Re: [PATCH net-next 3/6] genetlink: add helper for checking required attrs and use it in devlink
From: Jakub Kicinski <kuba@kernel.org>
Date: 2022-08-24 22:46:42
From: Jakub Kicinski <kuba@kernel.org>
Date: 2022-08-24 22:46:42
On Wed, 24 Aug 2022 21:44:22 +0200 Johannes Berg wrote:
On Tue, 2022-08-23 at 21:50 -0700, Jakub Kicinski wrote:quoted
+/* 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.)
Initially I typed up both flavors with and without the message but I dropped the _MSG() one since I didn't find a strong enough reason to use it. If we do get the _MSG() version at some point (perhaps to preserve an existing message during conversion?) having different case would seem off. I have no opinion which way is better, LMK if you prefer lower case (ignoring existing non-MSG helpers being upper case) and I'll sed thru the patches, no problem at all.