Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1899364rwd; Tue, 13 Jun 2023 16:23:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6iB5jg9ORXgsfwCzxr3rW57UDEpT5I2FpaHV9f4F9+Rjm/JXvMFPuO7DiIPzLyO5W8UTQi X-Received: by 2002:a17:90a:4f07:b0:25b:bd4d:bd18 with SMTP id p7-20020a17090a4f0700b0025bbd4dbd18mr286135pjh.16.1686698636385; Tue, 13 Jun 2023 16:23:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686698636; cv=none; d=google.com; s=arc-20160816; b=KAJmgrZnAfZ7dEgm4YxuxRWw5aHgQUez6+y15/MMrUmDGRUMdle/p6RG0CMawTIB+T 1O1QGhU7Aeg05vl93e9CNjCVe7/yacRSCRyiMwv2q+nhvqf+X7ES53p8o9chhn/1Doln pbj709S9UAgf/2PlNv8jmagiCpaT7ncTuWOfx6pqvnrHtVZ02Fy2dqkoQed+sbI2Yb4q JerCWxAbUX5IEYm8UK2q6MzgRC+a/ifxXEi4vcHzBDG1jetfnz06HboV+4euquka7nlW 0OXyZOIaGXvm8JX297i9nCDJXyTtqVGpgGrA7ifi0cZ4vSDzckL4YzJ9fAG+4ZJwnONo RQhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aISmU11WhU4Gc4ordprGFWD61d9QyG6tpbVKHZJCDCo=; b=QhFoYZyqatGT8bAd2/lPmCMeDSfafq0PxK5BIWw0U+RFzlkhF5n8psrFuZ+xUk4VGg Lc2nNo98sz88X8+qTtUsErL2ysyxPSW7vVisavuJKp4tQni5qDuJZ5eNZjMd/8iY76MS x1Se3+NFSII0bndDq8Qd/gLNAMGJW5udrtoN07kb5/t3m77VtT2Nq0l1OYRujP8+Kcr8 /FP9hGWuY8e2WlGvhuoI5EV1OpCyLiArNEkb/2nXmKgBenwTpOBc91DD+m6GoTcj+7bH 1+95Dykji0ivQwWw9DGYzL6Cs4AXmX60fEKDC0H20P/YkHtFNxMExNM2opNav5/fogoo 4AwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SCW7VtHH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k8-20020a17090aaa0800b00256a4676b7asi11202096pjq.14.2023.06.13.16.23.43; Tue, 13 Jun 2023 16:23:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SCW7VtHH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241379AbjFMXTX (ORCPT + 99 others); Tue, 13 Jun 2023 19:19:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230496AbjFMXTW (ORCPT ); Tue, 13 Jun 2023 19:19:22 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 072C219B2; Tue, 13 Jun 2023 16:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686698362; x=1718234362; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RQIhPr9DYeV1Rj7G2Tqjw0bFG1dfN/NDkAgtWqp7fi4=; b=SCW7VtHHNWZpX9Eum7EDW7QqpBJAY0VKNocjIBLXK6exN3ktJyh6wFmk VbUNnbCiD0Jfh/uxYuMUycmveyAerN0xGT7lV/KIgrxzlJdoAT1uV+aCY VC36BSvCgC2p750+mB77qPCfbtXPGoLogcjXRzv0E7AHCjVn+uU0iX0Wb cvb5PY4NHNU9mcJmOi5wlGRHmeoT78HozURupR3yjimtFolOJmQWi6FXT CutHKf07e4U3Me50BLYMD95mOKp61288oKUWKnEcrjYXYQHKiNfqGse9V YzK0zZbO7bLO7RKUqRsnchRuZvPfO7grlW/JS1OrlgwSb0QOlmn71iadM g==; X-IronPort-AV: E=McAfee;i="6600,9927,10740"; a="357352727" X-IronPort-AV: E=Sophos;i="6.00,241,1681196400"; d="scan'208";a="357352727" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2023 16:19:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10740"; a="777011241" X-IronPort-AV: E=Sophos;i="6.00,241,1681196400"; d="scan'208";a="777011241" Received: from amlin-018-114.igk.intel.com ([10.102.18.114]) by fmsmga008.fm.intel.com with ESMTP; 13 Jun 2023 16:19:19 -0700 From: Arkadiusz Kubalewski To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com, chuck.lever@oracle.com Cc: Arkadiusz Kubalewski Subject: [PATCH net-next] tools: ynl-gen: fix NLA_POLICY_MAX on enums with value Date: Wed, 14 Jun 2023 01:17:08 +0200 Message-Id: <20230613231709.150622-2-arkadiusz.kubalewski@intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230613231709.150622-1-arkadiusz.kubalewski@intel.com> References: <20230613231709.150622-1-arkadiusz.kubalewski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Policy defines max as length of enum list, if enum attribute is defined with a value, generated netlink policy max value is wrong. Calculate proper max value for policy where enums that are given explicit value. Signed-off-by: Arkadiusz Kubalewski --- tools/net/ynl/ynl-gen-c.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py index 4c12c6f8968e..9adcd785db0b 100755 --- a/tools/net/ynl/ynl-gen-c.py +++ b/tools/net/ynl/ynl-gen-c.py @@ -279,7 +279,16 @@ class TypeScalar(Type): elif 'enum' in self.attr: enum = self.family.consts[self.attr['enum']] cnt = len(enum['entries']) - return f"NLA_POLICY_MAX({policy}, {cnt - 1})" + values = [0] * cnt + for i in range(cnt): + if 'value' in enum['entries'][i]: + values[i] = enum['entries'][i]['value'] + else: + if i == 0: + values[i] = 0; + else: + values[i] = values[i - 1] + 1 + return f"NLA_POLICY_MAX({policy}, {max(values)})" return super()._attr_policy(policy) def _attr_typol(self): -- 2.37.3