From patchwork Mon Feb 13 18:56:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 56471 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2515455wrn; Mon, 13 Feb 2023 10:58:35 -0800 (PST) X-Google-Smtp-Source: AK7set8aUUnk1hfID/I4JTo89Smap8eRg/DfIv8xYifTpH5cNYs/Sjw6tYzri1Y+oxQMG3ARV0Q0 X-Received: by 2002:a17:906:f1c9:b0:88c:6345:d0e7 with SMTP id gx9-20020a170906f1c900b0088c6345d0e7mr25380756ejb.36.1676314715468; Mon, 13 Feb 2023 10:58:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676314715; cv=none; d=google.com; s=arc-20160816; b=DomT7NwTSqsQ8GJ9YQoW2L78puqLh1AWpcikdb7J4jESl32D0lXVIiS2ETc8odLzYF PxL4QVBIyKCjWZNh8DBVeZ1IT7BRw0IVF3Bwf3nfY2+M6kxA1T7EKxML/8NZ3Adhgk6t zYvkSChw6giiWZoUrztfWRFWU1aCJr8BQ6H7r1Qu+LTyQ0pw5Jqu3mnRFtCPBYqX1xLT oDEVSBEAWfzGtuGuHpxpPBEFrbiC62y6uKEcWk2QWCKwCoHKc+glOtTcm9kMx70DzGjC V80QZVj42x2mfBdMpQspjjO20/U0gQHsB3DUT1REYQgy4o1FdAM/xxBWsHvLaLOMtTGd rAvA== 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=nx9tTMJiSK3aN1a8Ha38HJ8pQWFwoYnzXFo+Xp9k7Yc=; b=Wbf6Es4RoDVo49zQxO8GvOomv48QkSBs7FczxKmVkzG3mCCPUMdhP34N3gC1OE7VnL EnA5vhmKr7tN7QBXjGdGD8172H+GwyxbUpV9s4LT7gqivvx5NLBOXpkTkjjQkjDNTOAx KqG5lFV/rW6gX27TfuMLcYqGZWxKhRSb0vR7GYng3gQQ4f0cnyAhQBy/xp3F3o1hzam5 AhKKXpjfK1WheANCZ21nwww8HHTGistTjYpCaOnV/8pOy/WlSQs6oZD8x3zN0IOd01A6 AzRP7DvBfkEwJJVC/EHF0GkZO2NuIkika3woljSAyF8lUNr84ywcH10FSKSIJJx9RY2M eVlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kdbR0U1u; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020aa7d4c8000000b004acbe7b3479si6380424edr.653.2023.02.13.10.58.11; Mon, 13 Feb 2023 10:58:35 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=kdbR0U1u; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230208AbjBMS5s (ORCPT + 99 others); Mon, 13 Feb 2023 13:57:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbjBMS5p (ORCPT ); Mon, 13 Feb 2023 13:57:45 -0500 Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B58EC1CAFA; Mon, 13 Feb 2023 10:57:44 -0800 (PST) Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-1442977d77dso16297431fac.6; Mon, 13 Feb 2023 10:57:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nx9tTMJiSK3aN1a8Ha38HJ8pQWFwoYnzXFo+Xp9k7Yc=; b=kdbR0U1uF6p9WpZYN9ndpHtdCvfkSHBZ3woLf3cQlVZh2ABRW2Zog/kv7JvC5k9MIJ y5e33kUGQk98Jwbe9Jkthe7mUM6aupcdEz4/GAvQ+UTkDs0xVLoNyCL5KAI0/T14qmih U73Zn+c1x0i7SUOfcfRsZQGhYRUSo3zwWyHWdDmHwPOXFp0Chhz3j6b27poHm+0+CNtZ uO94syer0odfNfw/L6HWcaOp3DQde+QnHtQRdtKvQnGGLqo+ZcvJOE+W8FV3RxDk5cC5 PWti4cip0uV/tvxuWMUkq2Z2SfE1HBoppSAvK8vk20SAyP404zmC/+uUn8vSsEhlNVoc t3eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nx9tTMJiSK3aN1a8Ha38HJ8pQWFwoYnzXFo+Xp9k7Yc=; b=5U3ffZ+iSX42dVFDGy4Y5Na7nPCaOWBLocjZoV4213Ehe+6HtoFZxgvX/uHvq07UlH EPaiXF4j2HfYQ7/BE/YfnkxUWu2uhuQM3bfcEkbXvYLoTqAlPFSZj9LEhZDqeNhk1+NA 0bpO2vGgjNCj4bVPhpJB0DNAvUI/QDwkE0rguQwCTc49NNdKydZ5aK5AFAhF+8WOwEbt mSvijSQE0vnIQHun9bYhtbjp1vwdJUsFi+ZB4cVcfQFP+isdVYsvJg6V0+EI+l7v/6lJ XMdMcjUT6c6jXmYoi6w3EbLpL5MM5L6qL7qtLPazUw/UNTccdixG+c/XcvBE6xsxRIma ILrA== X-Gm-Message-State: AO0yUKUrAoSf/hvLkrajMznkiGQ9kSyI5PrLWxG1xuYBuGBsw6AUPWA7 17O2UrlyZVoRi+1GFTuSrT8= X-Received: by 2002:a05:6870:8a20:b0:16e:676:bfea with SMTP id p32-20020a0568708a2000b0016e0676bfeamr2598306oaq.9.1676314664010; Mon, 13 Feb 2023 10:57:44 -0800 (PST) Received: from xps8900.attlocal.net ([2600:1700:2442:6db0:5829:dabf:a50e:e9f2]) by smtp.gmail.com with ESMTPSA id ef15-20020a0568701a8f00b0016df97ab05bsm1654958oab.31.2023.02.13.10.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 10:57:43 -0800 (PST) From: Frank Rowand To: Rob Herring Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/7] of: prepare to add processing of EXPECT_NOT to of_unittest_expect Date: Mon, 13 Feb 2023 12:56:56 -0600 Message-Id: <20230213185702.395776-2-frowand.list@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213185702.395776-1-frowand.list@gmail.com> References: <20230213185702.395776-1-frowand.list@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757743379123887820?= X-GMAIL-MSGID: =?utf-8?q?1757743379123887820?= scripts/dtc/of_unittest_expect processes EXPECT messages that document expected kernel messages triggered by unittest. Add processing of EXPECT_NOT messages that document kernel messages triggered by unittest that are not expected. This is commit 1 of 2, renaming existing variables in anticipation of the changes needed to process EXPECT_NOT, so that commit 2 of 2 will be smaller and easier to read. This commit is not intended to make any functional changes. Signed-off-by: Frank Rowand --- scripts/dtc/of_unittest_expect | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/dtc/of_unittest_expect b/scripts/dtc/of_unittest_expect index 96b12d9ea606..7b25bb693162 100755 --- a/scripts/dtc/of_unittest_expect +++ b/scripts/dtc/of_unittest_expect @@ -9,7 +9,7 @@ # on the console log that results from executing the Linux kernel # devicetree unittest (drivers/of/unitest.c). -$VUFX = "220201a"; +$VUFX = "230121a"; use strict 'refs'; use strict subs; @@ -274,7 +274,7 @@ while ($line = ) { if ($line =~ /^\s*$exp_begin/) { $data = $line; $data =~ s/^\s*$exp_begin//; - push @begin, $data; + push @exp_begin_stack, $data; if ($verbose) { if ($print_line_num) { @@ -302,20 +302,20 @@ while ($line = ) { $found = 0; $no_begin = 0; - if (@found_or_begin > 0) { - $begin = pop @found_or_begin; + if (@exp_found_or_begin > 0) { + $begin = pop @exp_found_or_begin; if (compare($data, $begin)) { $found = 1; } } elsif (@begin > 0) { - $begin = pop @begin; + $begin = pop @exp_begin_stack; } else { $no_begin = 1; } if ($no_begin) { - $expect_missing_begin++; + $exp_missing_begin++; print "** ERROR: EXPECT end without any EXPECT begin:\n"; print " end ---> $line\n"; @@ -325,20 +325,20 @@ while ($line = ) { $line_num = sprintf("%4s ", $.); } - $expect_not_found++; + $exp_missing++; printf "** %s%s$script_name WARNING - not found ---> %s\n", $line_num, $timestamp, $data; } elsif (! compare($data, $begin)) { - $expect_missing_end++; + $exp_missing_end++; print "** ERROR: EXPECT end does not match EXPECT begin:\n"; print " begin -> $begin\n"; print " end ---> $line\n"; } else { - $expect_found++; + $exp_found++; } @@ -357,7 +357,7 @@ while ($line = ) { } $found = 0; - foreach $begin (@begin) { + foreach $begin (@exp_begin_stack) { if (compare($begin, $line)) { $found = 1; last; @@ -365,12 +365,12 @@ while ($line = ) { } if ($found) { - $begin = shift @begin; + $begin = shift @exp_begin_stack; while (! compare($begin, $line)) { - push @found_or_begin, $begin; - $begin = shift @begin; + push @exp_found_or_begin, $begin; + $begin = shift @exp_begin_stack; } - push @found_or_begin, $line; + push @exp_found_or_begin, $line; if ($hide_expect) { $suppress_line = 1; @@ -391,18 +391,18 @@ if (! $no_expect_stats) { print "\n"; print "** EXPECT statistics:\n"; print "**\n"; - printf "** EXPECT found : %4i\n", $expect_found; - printf "** EXPECT not found : %4i\n", $expect_not_found; - printf "** missing EXPECT begin : %4i\n", $expect_missing_begin; - printf "** missing EXPECT end : %4i\n", $expect_missing_end; + printf "** EXPECT found : %4i\n", $exp_found; + printf "** EXPECT not found : %4i\n", $exp_missing; + printf "** missing EXPECT begin : %4i\n", $exp_missing_begin; + printf "** missing EXPECT end : %4i\n", $exp_missing_end; printf "** unittest FAIL : %4i\n", $unittest_fail; printf "** internal error : %4i\n", $internal_err; } -if (@begin) { +if (@exp_begin_stack) { print "** ERROR: EXPECT begin without any EXPECT end:\n"; print " This list may be misleading.\n"; - foreach $begin (@begin) { + foreach $begin (@exp_begin_stack) { print " begin ---> $begin\n"; } } From patchwork Mon Feb 13 18:56:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 56472 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2515474wrn; Mon, 13 Feb 2023 10:58:38 -0800 (PST) X-Google-Smtp-Source: AK7set9qdxeOmWZHe098Vc1rvITPzdCh1gP0CmYbgodoh37OhdSI9o4egz7WHEzj/aijYBP+8tw7 X-Received: by 2002:a17:906:2302:b0:878:6b39:6d2a with SMTP id l2-20020a170906230200b008786b396d2amr28341204eja.46.1676314717978; Mon, 13 Feb 2023 10:58:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676314717; cv=none; d=google.com; s=arc-20160816; b=a5IQHRuCQ/X9u553BLfpsXcdXReBGxmz8fpeNDcctcyvC5UmgLUTP+z0fxj6VlGjZV 3ZpQ8qhv0NcEG7xjKIt8dqHKZJOlKAeL5k40fBOzVeVIwQgnB9p0lqkAGgDlvVRYTRIe 8/x1vK7xQ0jRWN0jUCUEi32nIkufbyLMD5t7rVuQwwnnJhxAiJqT27aEIrRB1GcDLjVU SNHDlDeEANieIQXWWZfU6H6M31wVPo7yWNiT392S/85Vvd9Qu0/fX4JtCRCam06i12vo RKyoIlPw05JO2I8veqdMBuZBgx3gvbe+4F9EBOAUENiTIjyI3McEXI+CjdD/JyKhSm4n tgFw== 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=l2Ija/xk/Xo2pgXxKw0oJtRB4E5NlGaSmHRfzbCfeiQ=; b=LP99wlmmdMXnyCuj+n0Jr3IlgdPwy/sj1RVtIONRZSnDIrYCD5EwjxdCm+MkzeoO1Y ZJT5KOqqa2+ijXsmrxRyp496nv3QXjUQAZEPzzjBgGVtiU80pVrLHRmLCZDMo9P8J0vd KP+mkeNIalEvZo+dLkjR7KLa886dQx9Qff0dg1XjIFOw1QuzpQLnTjally0dSruv64Oh I7OsvV8RIAm82UNqqOZIN9byXlLUd58Uf1IA6ccd43YBkDo8QtB+D7viiuljBfBDYZ5v X8G5CCOeFf5Wwi56g7XvDdcCy8C9rKgCRdlnSntl2/jvdIubL0dGbwOmbWVj7VBZL6wD EqHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Xd6GCFHf; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 2-20020a17090601c200b008b120f21062si1271264ejj.584.2023.02.13.10.58.15; Mon, 13 Feb 2023 10:58:37 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=Xd6GCFHf; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230211AbjBMS5w (ORCPT + 99 others); Mon, 13 Feb 2023 13:57:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230157AbjBMS5q (ORCPT ); Mon, 13 Feb 2023 13:57:46 -0500 Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92DE9DBEE; Mon, 13 Feb 2023 10:57:45 -0800 (PST) Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-16debd2786aso6418684fac.7; Mon, 13 Feb 2023 10:57:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l2Ija/xk/Xo2pgXxKw0oJtRB4E5NlGaSmHRfzbCfeiQ=; b=Xd6GCFHfxB5FndpuQ2ZmtVl7YnsK2pEcHH4HNYPU10TMvtQZ2tnTN8Id5adCWNTzN7 nRRQcfjQ9WDSQYxA7uvOQwOrmDSk9ec5ZLk2N0g5gsDVG9GLtKPJSMIPQnieoU26/Tn4 PZhiJapmfRLK1q7/22I3+sAd2I8jMKSyEX53jUde2LA+vVJv+h5R25d2bGonYd07dL+e 3jIG47LwbIVSzP2279Fo/1DG8XXae3HtE4vgS26HJH3TVWQJmVn35cC6lBHl1pnT+HQK OLCr2s3iRQy9YY5750lI6FJ2wBgzJyglW4CDOF3IwD2V7rBIBVEZeFHYU/7tzP/N7XPg dgIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l2Ija/xk/Xo2pgXxKw0oJtRB4E5NlGaSmHRfzbCfeiQ=; b=XLV/RRL7FdJc3CxCIXlSnpXx17dFoHdsroFRxE63xnyST5RjMMAM3BW//3l34hj8ys 09cjhRr6MYW5L5xflBJoGM5WewgtqQx/nyniRcp8j/b85ZcSS9qwQFFJ6xz8CZDH8Ojx vJyN1qWHbf8bw6gOw1vEmuBjVSS/UgsCLR6uyebCOyyN2faZm+n0pYceBnsKEyfiNcyO jf4kYDgWEGeFofKfwHZHW2zFgy11cKAvSuoNlRWBp+DRA64YQCW6G01qWHT/VA4eBSbf jEcW+OMpHVu+ggRpKy0d3s1y7JzcNP6I85aAZ7RCcQi+15ZWulzOVwv5nK3AGteHt0Dq 6CEg== X-Gm-Message-State: AO0yUKXUxvXt6h8OYzsBnsXZp+dYG+kjETqT/t6osbmoZJsq6e80KKeP H0Os3kddvCWBpm2tDei4r34= X-Received: by 2002:a05:6871:68e:b0:16e:121b:7e69 with SMTP id l14-20020a056871068e00b0016e121b7e69mr2198173oao.6.1676314664899; Mon, 13 Feb 2023 10:57:44 -0800 (PST) Received: from xps8900.attlocal.net ([2600:1700:2442:6db0:5829:dabf:a50e:e9f2]) by smtp.gmail.com with ESMTPSA id ef15-20020a0568701a8f00b0016df97ab05bsm1654958oab.31.2023.02.13.10.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 10:57:44 -0800 (PST) From: Frank Rowand To: Rob Herring Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] of: add processing of EXPECT_NOT to of_unittest_expect Date: Mon, 13 Feb 2023 12:56:57 -0600 Message-Id: <20230213185702.395776-3-frowand.list@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213185702.395776-1-frowand.list@gmail.com> References: <20230213185702.395776-1-frowand.list@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757743381868948953?= X-GMAIL-MSGID: =?utf-8?q?1757743381868948953?= scripts/dtc/of_unittest_expect processes EXPECT messages that document expected kernel messages triggered by unittest. Add processing of EXPECT_NOT messages that document kernel messages triggered by unittest that are not expected. This is commit 2 of 2, implementing the processing of EXPECT_NOT messages. Signed-off-by: Frank Rowand --- scripts/dtc/of_unittest_expect | 157 ++++++++++++++++++++++++++++++--- 1 file changed, 145 insertions(+), 12 deletions(-) diff --git a/scripts/dtc/of_unittest_expect b/scripts/dtc/of_unittest_expect index 7b25bb693162..0a535a8e9821 100755 --- a/scripts/dtc/of_unittest_expect +++ b/scripts/dtc/of_unittest_expect @@ -9,7 +9,7 @@ # on the console log that results from executing the Linux kernel # devicetree unittest (drivers/of/unitest.c). -$VUFX = "230121a"; +$VUFX = "230211a"; use strict 'refs'; use strict subs; @@ -62,6 +62,8 @@ sub compare { } else { return 0; } + } elsif ($type eq "all") { + return 1; } elsif ($type eq "") { if ($expect_next ne $got_next) { return 0; @@ -130,6 +132,7 @@ usage: <> matches: [+-]*[0-9]+ <> matches: (0x)*[0-9a-f]+ + <> matches: anything to end of line 'EXPECT \\' (begin) and 'EXPECT /' (end) lines are suppressed. @@ -240,6 +243,8 @@ if ($#ARGV != 0) { $pr_fmt = "### dt-test ### "; $exp_begin = "${pr_fmt}EXPECT \\\\ : "; $exp_end = "${pr_fmt}EXPECT / : "; +$expnot_begin = "${pr_fmt}EXPECT_NOT \\\\ : "; +$expnot_end = "${pr_fmt}EXPECT_NOT / : "; $line_num = ""; @@ -250,6 +255,8 @@ while ($line = ) { chomp $line; + $suppress_line = 0; + $prefix = " "; ## 2 characters @@ -306,6 +313,7 @@ while ($line = ) { $begin = pop @exp_found_or_begin; if (compare($data, $begin)) { $found = 1; + $exp_found++; } } elsif (@begin > 0) { $begin = pop @exp_begin_stack; @@ -316,7 +324,7 @@ while ($line = ) { if ($no_begin) { $exp_missing_begin++; - print "** ERROR: EXPECT end without any EXPECT begin:\n"; + print "** ERROR: EXPECT end without matching EXPECT begin:\n"; print " end ---> $line\n"; } elsif (! $found) { @@ -329,17 +337,97 @@ while ($line = ) { printf "** %s%s$script_name WARNING - not found ---> %s\n", $line_num, $timestamp, $data; - } elsif (! compare($data, $begin)) { + } elsif (! compare($data, $begin) and ($data ne $begin)) { $exp_missing_end++; print "** ERROR: EXPECT end does not match EXPECT begin:\n"; print " begin -> $begin\n"; print " end ---> $line\n"; + } + + next LINE; + } + + + # ----- find EXPECT_NOT begin + + if ($line =~ /^\s*$expnot_begin/) { + $data = $line; + $data =~ s/^\s*$expnot_begin//; + push @expnot_begin_stack, $data; + + if ($verbose) { + if ($print_line_num) { + $line_num = sprintf("%4s ", $.); + } + printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line; + } + + next LINE; + } + + + # ----- find EXPECT_NOT end + + if ($line =~ /^\s*$expnot_end/) { + $data = $line; + $data =~ s/^\s*$expnot_end//; + + if ($verbose) { + if ($print_line_num) { + $line_num = sprintf("%4s ", $.); + } + printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line; + } + + $found = 0; + $no_begin = 0; + if (@expnot_found_or_begin > 0) { + $begin = pop @expnot_found_or_begin; + if (compare($data, $begin)) { + $found = 1; + $expnot_found++; + } + } elsif (@expnot_begin_stack <= 0) { + $no_begin = 1; + } + + if ($no_begin) { + + $expnot_missing_begin++; + print "** ERROR: EXPECT_NOT end without matching EXPECT_NOT begin:\n"; + print " end ---> $line\n"; + + } + + if ($found) { + + if ($print_line_num) { + $line_num = sprintf("%4s ", $.); + } + + printf "** %s%s$script_name WARNING - next line matches EXPECT_NOT\n", + $line_num, $timestamp; + printf "** %s%s%s\n", $line_num, $timestamp, $line; + } else { - $exp_found++; + $expnot_missing++; + + } + + if (@expnot_begin_stack > 0) { + $begin = pop @expnot_begin_stack; + + if (! compare($data, $begin) and ($data ne $begin)) { + $expnot_missing_end++; + print "** ERROR: EXPECT_NOT end does not match EXPECT_NOT begin:\n"; + print " begin -> $begin\n"; + print " end ---> $line\n"; + + } } next LINE; @@ -374,12 +462,38 @@ while ($line = ) { if ($hide_expect) { $suppress_line = 1; - next LINE; } $prefix = "ok"; # 2 characters } + $found = 0; + foreach $begin (@expnot_begin_stack) { + if (compare($begin, $line)) { + $found = 1; + last; + } + } + + if ($found) { + $begin = shift @begin; + while (! compare($begin, $line)) { + push @expnot_found_or_begin, $begin; + $begin = shift @begin; + } + push @expnot_found_or_begin, $line; + + if ($hide_expect) { + $suppress_line = 1; + } + $prefix = "**"; # 2 characters + } + + + if ($suppress_line) { + next LINE; + } + if ($print_line_num) { $line_num = sprintf("%4s ", $.); } @@ -391,18 +505,37 @@ if (! $no_expect_stats) { print "\n"; print "** EXPECT statistics:\n"; print "**\n"; - printf "** EXPECT found : %4i\n", $exp_found; - printf "** EXPECT not found : %4i\n", $exp_missing; - printf "** missing EXPECT begin : %4i\n", $exp_missing_begin; - printf "** missing EXPECT end : %4i\n", $exp_missing_end; - printf "** unittest FAIL : %4i\n", $unittest_fail; - printf "** internal error : %4i\n", $internal_err; + printf "** non-zero values expected:\n"; + print "**\n"; + printf "** EXPECT found : %4i\n", $exp_found; + printf "** EXPECT_NOT not found : %4i\n", $expnot_missing; + print "**\n"; + printf "** zero values expected:\n"; + print "**\n"; + printf "** EXPECT not found : %4i\n", $exp_missing; + printf "** missing EXPECT begin : %4i\n", $exp_missing_begin; + printf "** missing EXPECT end : %4i\n", $exp_missing_end; + print "**\n"; + printf "** EXPECT_NOT found : %4i\n", $expnot_found; + printf "** missing EXPECT_NOT begin : %4i\n", $expnot_missing_begin; + printf "** missing EXPECT_NOT end : %4i\n", $expnot_missing_end; + print "**\n"; + printf "** unittest FAIL : %4i\n", $unittest_fail; + printf "** internal error : %4i\n", $internal_err; } if (@exp_begin_stack) { - print "** ERROR: EXPECT begin without any EXPECT end:\n"; + print "** ERROR: EXPECT begin without matching EXPECT end:\n"; print " This list may be misleading.\n"; foreach $begin (@exp_begin_stack) { print " begin ---> $begin\n"; } } + +if (@expnot_begin_stack) { + print "** ERROR: EXPECT_NOT begin without matching EXPECT_NOT end:\n"; + print " This list may be misleading.\n"; + foreach $begin (@expnot_begin_stack) { + print " begin ---> $begin\n"; + } +} From patchwork Mon Feb 13 18:56:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 56473 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2515576wrn; Mon, 13 Feb 2023 10:58:53 -0800 (PST) X-Google-Smtp-Source: AK7set9WCa3SpSfvfDvmbfAFy+7QTi9qFpQxYOedM2TRsW/gbJUgWN8pygUloDrEejL6O9iw4Yyk X-Received: by 2002:a17:906:a0d1:b0:883:be32:cd33 with SMTP id bh17-20020a170906a0d100b00883be32cd33mr31140653ejb.35.1676314733235; Mon, 13 Feb 2023 10:58:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676314733; cv=none; d=google.com; s=arc-20160816; b=S8X68zmk4sUyst5HnpMQmzyXh/CupS8x5NS38/17IlDKhq2AXUaM1bxNiMpEvH8ErB kHWx5KJdnEoUtFkOFEENWES3LGkkmIpjg0RnawewY1Lh0tv8PO6bYDH/a5hKxGIZI7R7 hVenIfbATMkgx4meae0O+94gonjVvctzsKOsRwgp26jWtGf7nQ8T6WLSYcd1XcWFKZHn u8KuP7bbc03gf7T8Q90HZyBBJxJgbmdtjRCyGcddCsILCW9/Ju/F9fNmA/7CuLJ6Vlyh zn1q5GiNarOKGBN0Iup0WhYW5BTqmXzIimscS/B1wXZABJRY2qBiSldVsKKRYh1ph6D1 LnHA== 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=kHyn+Iq5kDFceNl3I1U0GgQ46vN33MHSRz9J5NGp5vU=; b=Sr0wzCwIFo1bvOA8XZxm2KBSvtuFUtYE+d4V82wm4etFvi6bf5hf5XKtLlzJhFjajF Vu9xjWN1A8u4rhUNOJG1653tWfnnLXJ4eEX/bioURnDoF7iBYfjIlQJMHiUbwJNh93+i 3LrtrnY0ECF60KyFj83bUbHsYK9/7DT5CQuI9r8mvHhkqviTp21J8VWkWDjDn1JI7qAR 8mr4RfZQ/RAl5NRyZCTyEL1jB//RCOXEoy9ALm2myVQvv/q8AklSLON6cOjN6dzSsipp XSdOkxpSxPaBqIKH+BA7LNLJ8zAnMjunqj9CWYWPuk95Qa+aOWwn7PdBudKWOq3wxzIL wVXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=U7JpZQ1g; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wg15-20020a1709078f0f00b008a9a111ce8dsi13432688ejc.4.2023.02.13.10.58.30; Mon, 13 Feb 2023 10:58:53 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=U7JpZQ1g; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230361AbjBMS57 (ORCPT + 99 others); Mon, 13 Feb 2023 13:57:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230160AbjBMS5r (ORCPT ); Mon, 13 Feb 2023 13:57:47 -0500 Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D347126E5; Mon, 13 Feb 2023 10:57:46 -0800 (PST) Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-16a7f5b6882so16261768fac.10; Mon, 13 Feb 2023 10:57:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kHyn+Iq5kDFceNl3I1U0GgQ46vN33MHSRz9J5NGp5vU=; b=U7JpZQ1g9CQpoTz6vURu+kEOjs3644ilNrBedisqBKcqVEJHUBlupRfJwgqLsatmsW nZHnilMgjXEPezYlYBRISCkAKZGV+fgpAIUhvbUZi5HT8luC7CAgOVKsFgGrnIF6c0cI cxtvgvmk2o+ln4w1Uibo3ZNNoLaTgt+emFpNFbhSZFeDsDX643H6GaXxD0icFkiZozpT dlPqzwIHj46a3GTF/SxKI+xJeTQsttNdKdswDP2Ld7K+FMPbs76kTRln7sIrob3ptVNc NsEXnOu9SXViqe+DPs2TdQq88esSxvTWT+WDv9jHUohu+p2n6DPxGQJ+JWfmV4AtOy3w ajGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kHyn+Iq5kDFceNl3I1U0GgQ46vN33MHSRz9J5NGp5vU=; b=3cAdeUm0TkH4fEzm0wuLTl1Gy/GRN//C7I5q0RxJAitSNCdFQyxee62JUIFXFbd8pH G75qmT3mG5x4NUm3PKH2lerBZVSx/O4V8XvhRdb3BK78JEilQFZ1DZc5kkId8BRiuaq1 i20V6XHz38+UDqQRbRNclm3QdYHoh6gJjh3TNaDzvqmgbdUJXSO6ojaQPVoOMfvTTE1j ad76h5rGF+LNoTDKw2PfgldzV6WMwOyFSVBpM6w5SHwYkcIXLjrYRXfBAfVPAtJPXPsB hvfoW4Xhnz0xkGdYGdX0ucIwlP0UaxYn0WaDVn9kHOp8xa+EEQRPS5BptsnFVzIs8SYW Znhg== X-Gm-Message-State: AO0yUKU+5aN5wmH38b2gxrPXg2yq2WtJ2nAU2lgZ0av7VTs9oZxJXKp3 dGEpuBHE5yEmkRv+dxOLQmE= X-Received: by 2002:a05:6870:470e:b0:16a:a965:87e0 with SMTP id b14-20020a056870470e00b0016aa96587e0mr10937388oaq.54.1676314665730; Mon, 13 Feb 2023 10:57:45 -0800 (PST) Received: from xps8900.attlocal.net ([2600:1700:2442:6db0:5829:dabf:a50e:e9f2]) by smtp.gmail.com with ESMTPSA id ef15-20020a0568701a8f00b0016df97ab05bsm1654958oab.31.2023.02.13.10.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 10:57:45 -0800 (PST) From: Frank Rowand To: Rob Herring Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/7] of: update kconfig unittest help Date: Mon, 13 Feb 2023 12:56:58 -0600 Message-Id: <20230213185702.395776-4-frowand.list@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213185702.395776-1-frowand.list@gmail.com> References: <20230213185702.395776-1-frowand.list@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757743397584233673?= X-GMAIL-MSGID: =?utf-8?q?1757743397584233673?= Add more information about the impact the of unittests have on the live devicetree and why the tests should only be enabled for developer kernels. Add information about processing the test output such that the results are more complete and comprehendable. Signed-off-by: Frank Rowand --- drivers/of/Kconfig | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 80b5fd44ab1c..644386833a7b 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -23,7 +23,19 @@ config OF_UNITTEST that are executed once at boot time, and the results dumped to the console. - If unsure, say N here, but this option is safe to enable. + This option should only be enabled for a development kernel. The tests + will taint the kernel with TAINT_TEST. The tests will cause ERROR and + WARNING messages to print on the console. The tests will cause stack + traces to print on the console. It is possible that the tests will + leave the devicetree in a corrupted state. + + The unittest output will be verbose. Copy the output to a file + via capturing the console output or via the dmesg command. Process + this file with scripts/dtc/of_unittest_expect to reduce the + verbosity, test whether expected output is present, and to + summarize the results. + + If unsure, say N here. This option is not safe to enable. config OF_ALL_DTBS bool "Build all Device Tree Blobs" From patchwork Mon Feb 13 18:56:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 56475 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2515903wrn; Mon, 13 Feb 2023 10:59:36 -0800 (PST) X-Google-Smtp-Source: AK7set8YnvBKxNAN8lpHMYK/Ip3Bi02kg5Wu4LP+GhCv9/ksFyr1EWzahnIducYbI8/FzM32TFqJ X-Received: by 2002:a50:ab5a:0:b0:4ac:be42:5c66 with SMTP id t26-20020a50ab5a000000b004acbe425c66mr6519312edc.11.1676314776617; Mon, 13 Feb 2023 10:59:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676314776; cv=none; d=google.com; s=arc-20160816; b=vOO3rqQ5q2MpvosKUpPV1OM91nP6SES+ECNWpO2+gZKQTZg7paKWcdegZzK/rlwZMR Q221aA4vxhmq7ECx1IwZONbY8B26cg7ZYRK3X+oSK6givU6L/5qZM920XJWmgBL3j27F C5bDzaaG1cmmBZcSIAlrGnmsrTrhU77f+U6Dwbz44kb5De0a6FDzANlNRRpjElEtrs5U MpgDJqG36XWO7eiNtK83JKXFBGIds7rlNBMNc9MruwNkgMReq9vBIDwgZ99htvmckK2/ kIMVhxDFX95HmwXhMtCgeD1k2Pl7+a5hx3pJQKOZapvscXNiWOI2H0fC7Nn31yCH5OI7 Fr9g== 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=/UaMb/Ek1V0BcXomcbr9rAthrv86jIQSmg9UWV3JfZc=; b=O7ANotyqgE1RpxSWrHA8pUPYH7pWIy452kqg766mmpAh3LqZr22gzaxeqiHy9yT715 /lX53St2MRAp6aDa5ElZaN7lUairjgAiL3hmHWQ25eGzXUFpwAoSiNiS1UD/zvfKiES2 DHi9FHBYjgNHagfN9alDRVQubKcrqUr+z/3NH5Yglf4BW/2UC7AMMyb7zZ+FuTUJhDes iYvKT1bx9a6DiYnKjpT2khC8Ss2cVn58/dd4gI0TDnHoIj5DrBlQLXzv5R2LdZysxM/c 19S+eVa7iVwtVYJMKV4J+FGmk2NLcP8A86iI+uzlPJ04qWZWfUIRCKPB8eKqPCKhGcNF is2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hUAoilpH; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a056402104300b004acc42af72bsi5117967edu.359.2023.02.13.10.59.13; Mon, 13 Feb 2023 10:59:36 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=hUAoilpH; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230437AbjBMS6G (ORCPT + 99 others); Mon, 13 Feb 2023 13:58:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230232AbjBMS5t (ORCPT ); Mon, 13 Feb 2023 13:57:49 -0500 Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5508A20D0D; Mon, 13 Feb 2023 10:57:47 -0800 (PST) Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-16debd2786aso6418773fac.7; Mon, 13 Feb 2023 10:57:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/UaMb/Ek1V0BcXomcbr9rAthrv86jIQSmg9UWV3JfZc=; b=hUAoilpHaspOgb0khCYOk7X6KuHuLyueMkZwHWjzN91LG35vBdVbf/73zcFUzgCLR5 P99UD6U+KEeFsn1JzWTqwWTzHhs8rej7WVuG0VkJ78AxpCjlJqYG5NSXoIns5wqceWF/ rlWSUDye/ouaxGC50ylFmhrALG25gil4A7HEbZ4hGLXOKshTKjzhx48ja1PoJiDiL+0z rf9FZlyB8QvWvq6af6A60igXKIfg1QfihFVPAOLgtFz+rXP6FTwQeq+Gu3n0iZd9LqBZ y/kY9FS6UgbGTvd9SN/zX4ZQXfW2OLqeG/oAHtW9C1ebc2ntfTHq+Q4ANc7wDErXUBc1 vlIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/UaMb/Ek1V0BcXomcbr9rAthrv86jIQSmg9UWV3JfZc=; b=5ai9DjXkY1BKGoskhhtQ1qtfuTbyxjNQFnZOPQbsP4n7Jtoct4tj8KKESGaeOQVqaF IvtezGh9fCl0Bzlj3pVyY/hOP15eIFOzWpuoBeT63H4Pz2Ma+/xbZHdKxgHtAprtok2b SSGa10TWk/YSW31v7S+47hX5ZnDQuAZ3LXnMUGJWzeqJFkR7sA9AS9FxZ7hNwwAyUKSh touOPgslN05/3AkbSVf3Zzhk+Dwnb2lfOz1EpxCMmlbMSL31cts0jrEtoJbklghOnWsU qcP+WDrUvL5yLoTw+0fXMyODytW07zJraDUe1Ib2hcvuelYvKZU/c9DrH/INjn0P51xH 9QyA== X-Gm-Message-State: AO0yUKUORHEy1domRA3Dr9RrF3vKZQYxaODafoBbD8RfZy+wO+H5TY3W hrpKQXjiqnuQhiVSkPbEyPV9S30OdFQ= X-Received: by 2002:a05:6870:6487:b0:16e:2025:3564 with SMTP id cz7-20020a056870648700b0016e20253564mr1241982oab.35.1676314666543; Mon, 13 Feb 2023 10:57:46 -0800 (PST) Received: from xps8900.attlocal.net ([2600:1700:2442:6db0:5829:dabf:a50e:e9f2]) by smtp.gmail.com with ESMTPSA id ef15-20020a0568701a8f00b0016df97ab05bsm1654958oab.31.2023.02.13.10.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 10:57:46 -0800 (PST) From: Frank Rowand To: Rob Herring Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/7] of: unittest: add node lifecycle tests Date: Mon, 13 Feb 2023 12:56:59 -0600 Message-Id: <20230213185702.395776-5-frowand.list@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213185702.395776-1-frowand.list@gmail.com> References: <20230213185702.395776-1-frowand.list@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757743443184409569?= X-GMAIL-MSGID: =?utf-8?q?1757743443184409569?= Add tests to exercise the actions that occur when the reference count of devicetree nodes decrement to zero and beyond. Decrementing to zero triggers freeing memory allocated for the node. This commit will expose a pr_err() issue in of_node_release(), resulting in some kernal warnings and stack traces. When scripts/dtc/of_unittest_expect processes the console messages, it will also report related problems for EXPECT messages due to the pr_err() issue: ** missing EXPECT begin : 5 Signed-off-by: Frank Rowand --- There are checkpatch warnings. I have reviewed them and feel they can be ignored. Stack traces from the pr_err() issue: ------------[ cut here ]------------ WARNING: CPU: 0 PID: 1 at lib/refcount.c:25 kobject_get+0xa0/0xa4 refcount_t: addition on 0; use-after-free. Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Tainted: G N 6.2.0-rc1-00005-g774057a35a67 #21 Hardware name: Generic DT based system unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x40/0x4c dump_stack_lvl from __warn+0x7c/0x15c __warn from warn_slowpath_fmt+0x98/0xcc warn_slowpath_fmt from kobject_get+0xa0/0xa4 kobject_get from of_node_get+0x14/0x1c of_node_get from of_fwnode_get+0x34/0x40 of_fwnode_get from fwnode_full_name_string+0x34/0xa0 fwnode_full_name_string from device_node_string+0x4dc/0x4f4 device_node_string from pointer+0x364/0x598 pointer from vsnprintf+0x1f8/0x3d0 vsnprintf from vprintk_store+0x134/0x410 vprintk_store from vprintk_emit+0x6c/0x234 vprintk_emit from vprintk_default+0x20/0x28 vprintk_default from _printk+0x30/0x60 _printk from of_node_release+0xb0/0xf4 of_node_release from kobject_put+0xc4/0x29c kobject_put from of_unittest+0x256c/0x2eb8 of_unittest from do_one_initcall+0x4c/0x268 do_one_initcall from kernel_init_freeable+0x1b4/0x214 kernel_init_freeable from kernel_init+0x18/0x130 kernel_init from ret_from_fork+0x14/0x2c Exception stack(0xf0821fb0 to 0xf0821ff8) 1fa0: 00000000 00000000 00000000 00000000 1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 1fe0: 00000000 00000000 00000000 00000000 00000013 00000000 ---[ end trace 0000000000000000 ]--- ------------[ cut here ]------------ WARNING: CPU: 0 PID: 1 at lib/refcount.c:28 fwnode_full_name_string+0x8c/0xa0 refcount_t: underflow; use-after-free. Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Tainted: G W N 6.2.0-rc1-00005-g774057a35a67 #21 Hardware name: Generic DT based system unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x40/0x4c dump_stack_lvl from __warn+0x7c/0x15c __warn from warn_slowpath_fmt+0x98/0xcc warn_slowpath_fmt from fwnode_full_name_string+0x8c/0xa0 fwnode_full_name_string from device_node_string+0x4dc/0x4f4 device_node_string from pointer+0x364/0x598 pointer from vsnprintf+0x1f8/0x3d0 vsnprintf from vprintk_store+0x134/0x410 vprintk_store from vprintk_emit+0x6c/0x234 vprintk_emit from vprintk_default+0x20/0x28 vprintk_default from _printk+0x30/0x60 _printk from of_node_release+0xb0/0xf4 of_node_release from kobject_put+0xc4/0x29c kobject_put from of_unittest+0x256c/0x2eb8 of_unittest from do_one_initcall+0x4c/0x268 do_one_initcall from kernel_init_freeable+0x1b4/0x214 kernel_init_freeable from kernel_init+0x18/0x130 kernel_init from ret_from_fork+0x14/0x2c Exception stack(0xf0821fb0 to 0xf0821ff8) 1fa0: 00000000 00000000 00000000 00000000 1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 1fe0: 00000000 00000000 00000000 00000000 00000013 00000000 ---[ end trace 0000000000000000 ]--- ------------[ cut here ]------------ WARNING: CPU: 0 PID: 1 at lib/refcount.c:22 kobject_get+0x8c/0xa4 refcount_t: saturated; leaking memory. Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Tainted: G W N 6.2.0-rc1-00005-g774057a35a67 #21 Hardware name: Generic DT based system unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x40/0x4c dump_stack_lvl from __warn+0x7c/0x15c __warn from warn_slowpath_fmt+0x98/0xcc warn_slowpath_fmt from kobject_get+0x8c/0xa4 kobject_get from of_node_get+0x14/0x1c of_node_get from of_fwnode_get+0x34/0x40 of_fwnode_get from fwnode_full_name_string+0x34/0xa0 fwnode_full_name_string from device_node_string+0x4dc/0x4f4 device_node_string from pointer+0x364/0x598 pointer from vsnprintf+0x1f8/0x3d0 vsnprintf from vscnprintf+0x10/0x24 vscnprintf from printk_sprint+0x18/0x194 printk_sprint from vprintk_store+0x378/0x410 vprintk_store from vprintk_emit+0x6c/0x234 vprintk_emit from vprintk_default+0x20/0x28 vprintk_default from _printk+0x30/0x60 _printk from of_node_release+0xb0/0xf4 of_node_release from kobject_put+0xc4/0x29c kobject_put from of_unittest+0x256c/0x2eb8 of_unittest from do_one_initcall+0x4c/0x268 do_one_initcall from kernel_init_freeable+0x1b4/0x214 kernel_init_freeable from kernel_init+0x18/0x130 kernel_init from ret_from_fork+0x14/0x2c Exception stack(0xf0821fb0 to 0xf0821ff8) 1fa0: 00000000 00000000 00000000 00000000 1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 1fe0: 00000000 00000000 00000000 00000000 00000013 00000000 ---[ end trace 0000000000000000 ]--- drivers/of/dynamic.c | 14 +- .../of/unittest-data/testcases_common.dtsi | 1 + drivers/of/unittest-data/tests-lifecycle.dtsi | 8 + drivers/of/unittest.c | 148 +++++++++++++++++- 4 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 drivers/of/unittest-data/tests-lifecycle.dtsi diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index cd3821a6444f..becb80f762c8 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -332,7 +332,19 @@ void of_node_release(struct kobject *kobj) /* We should never be releasing nodes that haven't been detached. */ if (!of_node_check_flag(node, OF_DETACHED)) { pr_err("ERROR: Bad of_node_put() on %pOF\n", node); - dump_stack(); + + /* + * of unittests will test this path. Do not print the stack + * trace when the error is caused by unittest so that we do + * not display what a normal developer might reasonably + * consider a real bug. + */ + if (!IS_ENABLED(CONFIG_OF_UNITTEST) || + strcmp(node->parent->full_name, "testcase-data")) { + dump_stack(); + pr_err("ERROR: next of_node_put() on this node will result in a kboject warning 'refcount_t: underflow; use-after-free.'\n"); + } + return; } if (!of_node_check_flag(node, OF_DYNAMIC)) diff --git a/drivers/of/unittest-data/testcases_common.dtsi b/drivers/of/unittest-data/testcases_common.dtsi index 19292bbb4cbb..e7887f2301c1 100644 --- a/drivers/of/unittest-data/testcases_common.dtsi +++ b/drivers/of/unittest-data/testcases_common.dtsi @@ -17,3 +17,4 @@ node-remove { #include "tests-address.dtsi" #include "tests-platform.dtsi" #include "tests-overlay.dtsi" +#include "tests-lifecycle.dtsi" diff --git a/drivers/of/unittest-data/tests-lifecycle.dtsi b/drivers/of/unittest-data/tests-lifecycle.dtsi new file mode 100644 index 000000000000..28509a8783a7 --- /dev/null +++ b/drivers/of/unittest-data/tests-lifecycle.dtsi @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 + +/ { + testcase-data { + refcount-node { + }; + }; +}; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index bc0f1e50a4be..db72e208819c 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -54,8 +54,9 @@ static struct unittest_results { * Print the expected message only if the current loglevel will allow * the actual message to print. * - * Do not use EXPECT_BEGIN() or EXPECT_END() for messages generated by - * pr_debug(). + * Do not use EXPECT_BEGIN(), EXPECT_END(), EXPECT_NOT_BEGIN(), or + * EXPECT_NOT_END() to report messages expected to be reported or not + * reported by pr_debug(). */ #define EXPECT_BEGIN(level, fmt, ...) \ printk(level pr_fmt("EXPECT \\ : ") fmt, ##__VA_ARGS__) @@ -63,6 +64,12 @@ static struct unittest_results { #define EXPECT_END(level, fmt, ...) \ printk(level pr_fmt("EXPECT / : ") fmt, ##__VA_ARGS__) +#define EXPECT_NOT_BEGIN(level, fmt, ...) \ + printk(level pr_fmt("EXPECT_NOT \\ : ") fmt, ##__VA_ARGS__) + +#define EXPECT_NOT_END(level, fmt, ...) \ + printk(level pr_fmt("EXPECT_NOT / : ") fmt, ##__VA_ARGS__) + static void __init of_unittest_find_node_by_name(void) { struct device_node *np; @@ -1488,6 +1495,7 @@ static int __init unittest_data_add(void) struct device_node *next = np->sibling; np->parent = of_root; + /* this will clear OF_DETACHED in np and children */ attach_node_and_children(np); np = next; } @@ -2998,6 +3006,141 @@ static void __init of_unittest_overlay(void) static inline void __init of_unittest_overlay(void) { } #endif +static void __init of_unittest_lifecycle(void) +{ + unsigned int refcount; + int found_refcount_one = 0; + int put_count = 0; + struct device_node *np; + struct device_node *prev_sibling, *next_sibling; + const char *refcount_path = "/testcase-data/refcount-node"; + const char *refcount_parent_path = "/testcase-data"; + + /* + * Node lifecycle tests, non-dynamic node: + * + * - Decrementing refcount to zero via of_node_put() should cause the + * attempt to free the node memory by of_node_release() to fail + * because the node is not a dynamic node. + * + * - Decrementing refcount past zero should result in additional + * errors reported. + */ + + np = of_find_node_by_path(refcount_path); + unittest(np, "find refcount_path \"%s\"\n", refcount_path); + if (np == NULL) + goto out_skip_tests; + + while (!found_refcount_one) { + + if (put_count++ > 10) { + unittest(0, "guardrail to avoid infinite loop\n"); + goto out_skip_tests; + } + + refcount = kref_read(&np->kobj.kref); + if (refcount == 1) + found_refcount_one = 1; + else + of_node_put(np); + } + + EXPECT_BEGIN(KERN_INFO, "OF: ERROR: of_node_release() detected bad of_node_put() on /testcase-data/refcount-node"); + + /* + * refcount is now one, decrementing to zero will result in a call to + * of_node_release() to free the node's memory, which should result + * in an error + */ + unittest(1, "/testcase-data/refcount-node is one"); + of_node_put(np); + + EXPECT_END(KERN_INFO, "OF: ERROR: of_node_release() detected bad of_node_put() on /testcase-data/refcount-node"); + + + /* + * expect stack trace for subsequent of_node_put(): + * __refcount_sub_and_test() calls: + * refcount_warn_saturate(r, REFCOUNT_SUB_UAF) + * + * Not capturing entire WARN_ONCE() trace with EXPECT_*(), just + * the first three lines, and the last line. + */ + EXPECT_BEGIN(KERN_INFO, "------------[ cut here ]------------"); + EXPECT_BEGIN(KERN_INFO, "WARNING: <>"); + EXPECT_BEGIN(KERN_INFO, "refcount_t: underflow; use-after-free."); + EXPECT_BEGIN(KERN_INFO, "---[ end trace <> ]---"); + + /* refcount is now zero, this should fail */ + unittest(1, "/testcase-data/refcount-node is zero"); + of_node_put(np); + + EXPECT_END(KERN_INFO, "---[ end trace <> ]---"); + EXPECT_END(KERN_INFO, "refcount_t: underflow; use-after-free."); + EXPECT_END(KERN_INFO, "WARNING: <>"); + EXPECT_END(KERN_INFO, "------------[ cut here ]------------"); + + /* + * Q. do we expect to get yet another warning? + * A. no, the WARNING is from WARN_ONCE() + */ + EXPECT_NOT_BEGIN(KERN_INFO, "------------[ cut here ]------------"); + EXPECT_NOT_BEGIN(KERN_INFO, "WARNING: <>"); + EXPECT_NOT_BEGIN(KERN_INFO, "refcount_t: underflow; use-after-free."); + EXPECT_NOT_BEGIN(KERN_INFO, "---[ end trace <> ]---"); + + unittest(1, "/testcase-data/refcount-node is zero, second time"); + of_node_put(np); + + EXPECT_NOT_END(KERN_INFO, "---[ end trace <> ]---"); + EXPECT_NOT_END(KERN_INFO, "refcount_t: underflow; use-after-free."); + EXPECT_NOT_END(KERN_INFO, "WARNING: <>"); + EXPECT_NOT_END(KERN_INFO, "------------[ cut here ]------------"); + + /* + * refcount of zero will trigger stack traces from any further + * attempt to of_node_get() node "refcount-node". One example of + * this is where of_unittest_check_node_linkage() will recursively + * scan the tree, with 'for_each_child_of_node()' doing an + * of_node_get() of the children of a node. + * + * Prevent the stack trace by removing node "refcount-node" from + * its parent's child list. + * + * WARNING: EVIL, EVIL, EVIL: + * + * Directly manipulate the child list of node /testcase-data to + * remove child refcount-node. This is ignoring all proper methods + * of removing a child and will leak a small amount of memory. + */ + + np = of_find_node_by_path(refcount_parent_path); + unittest(np, "find refcount_parent_path \"%s\"\n", refcount_parent_path); + unittest(np, "ERROR: devicetree live tree left in a 'bad state' if test fail\n"); + if (np == NULL) + return; + + prev_sibling = np->child; + next_sibling = prev_sibling->sibling; + if (!strcmp(prev_sibling->full_name, "refcount-node")) { + np->child = next_sibling; + next_sibling = next_sibling->sibling; + } + while (next_sibling) { + if (!strcmp(next_sibling->full_name, "refcount-node")) + prev_sibling->sibling = next_sibling->sibling; + prev_sibling = next_sibling; + next_sibling = next_sibling->sibling; + } + of_node_put(np); + + return; + +out_skip_tests: + unittest(0, "One or more lifecycle tests skipped\n"); +} + #ifdef CONFIG_OF_OVERLAY /* @@ -3502,6 +3645,7 @@ static int __init of_unittest(void) of_unittest_match_node(); of_unittest_platform_populate(); of_unittest_overlay(); + of_unittest_lifecycle(); /* Double check linkage after removing testcase data */ of_unittest_check_tree_linkage(); From patchwork Mon Feb 13 18:57:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 56474 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2515885wrn; Mon, 13 Feb 2023 10:59:33 -0800 (PST) X-Google-Smtp-Source: AK7set+2en5sBCXtFSgoRHISvhf8eyy2FqRUlXSz/2+NxkehS70DpCdJugVJd7xEkfKjUNEavRaI X-Received: by 2002:a50:cd06:0:b0:4aa:c3da:3ac5 with SMTP id z6-20020a50cd06000000b004aac3da3ac5mr28095068edi.3.1676314773793; Mon, 13 Feb 2023 10:59:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676314773; cv=none; d=google.com; s=arc-20160816; b=pDL1RwXjdZJ70cVRBouaQyt0uQcl8EXip7T17KUlBy/tSr+xkT5TVtfogMtT+QLSVF oLbHT1o6ilrxAmqxmSCbu9BA7NwFtimzwbRV8egSbNe3MTwmuPl5Xokw4NdA0KUPjJ9L OvP6paUizhFOUHfBqsiNoqu7o5LVuKdm/3U6I5NHjT8aGMhCIxBiMvtVINiXSe37TEyo Fabk8yDFWpOlnXinMYJeN1k9UxGhKLsjR4e43hxlUMjyFpPxMUeXXP1r/nDefDrrSZPg SKe6+susGYDsZzEa1bhPfDJXyQsZxQu9OJKscxQynuWcgUAHWSvxbaCE1OTiidG7GgMM v4qA== 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=25JgBmt061z2zUT7Rn2AWSIssQrUdgZ1DK2ZqeBawkI=; b=HiquaGt7junnd/QTvuX7Rn/qTVrYbWs7IdcO3we1qDbJq+hwNoJ5MiGgNLVHq7ahtp wMdUWbvlR6aNiPPhjNLgcBe3vMq/Y8YDRzfXwCcbjuaqHFLVBGDLw8fDbMCm94PK1xLa DJD9WKIJluYX4n5TM0zUHeTXg4q+EWUrjyHsyIkOUkcmskUMVjaed4RZcBrm5u2dHWl7 VRSzIIueNx4y3xNGRIWASS97kXIlUFABy5osjo4JprNyiEZFiXEcOg3TaZ77yFqyPjCS yKiAiELTNvhN0dumEJlFRqjx2BKZ7oNDXrbfI9cjRLt6JZ47EPnUIRx779CHZQjR/fzw cxWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=L084l8ve; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a25-20020aa7cf19000000b004acd34e9368si1169211edy.187.2023.02.13.10.59.10; Mon, 13 Feb 2023 10:59:33 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=L084l8ve; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230409AbjBMS6D (ORCPT + 99 others); Mon, 13 Feb 2023 13:58:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230216AbjBMS5t (ORCPT ); Mon, 13 Feb 2023 13:57:49 -0500 Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C52ECE; Mon, 13 Feb 2023 10:57:48 -0800 (PST) Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-16aa71c1600so16261621fac.11; Mon, 13 Feb 2023 10:57:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=25JgBmt061z2zUT7Rn2AWSIssQrUdgZ1DK2ZqeBawkI=; b=L084l8ve1Ciy9gxw+ILSf96unYRjmyPf/PxoHxG+SxAAX/2DkIR2JvJHS2CqbB8XjA kw+KBbylhH6Ewqr6jyhyjsOPA9LaRrWw1f9I/okg+5dHf0DDj8PKvJwLQNddwuez8X6l Jkn4NWYHgEK5+pvjxE38jgrCXnkuBStmnktqTWGfVWyGsTiQVPO2UxRr/hwQqdqVSi52 crKpqNqQDwXs4fJVe3fR0uMIQ6Dnid2mZLM0tYl/nYcWPeWq4iVAxM4sB4fvG+Qn3OHJ coJcHRycyNmV9ebEADPcWVT7Mso4QDkl/Fhzg8b/3Ol6f78ao/Bcc9O5nqg7vC6Tlhc5 CaAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=25JgBmt061z2zUT7Rn2AWSIssQrUdgZ1DK2ZqeBawkI=; b=2xv3sHDq5bEc+08inDKH5JBgp8H4VuOmjOky6AHwYGZWJuG5cxm4XW3PDftJUdlGtC fU/gtB2Qr33QudRKtnlhpJb3Xe9QGBeo8Cuc+3XnExUrRghfbps2aONiOBokoSWz9NXi HEHuujSH+WE3KXq+fSpdtnIjx8SLDcJ75ZQc2vnhpSj4t+feP1vOf3yvB1wDbp8nS+O6 kBZh6kwgERp2/zidNjaiTC5JBF+zRXQyu/p/cEtqPq9gkAABU4girkOHCB9uvH2UHTxf YfePILTJtwjKIEJcjEuDCHeqHpNTaGlS+slrInoLwAK5eLUjZTYGUtUC/f6YWV5oXRhY YCMA== X-Gm-Message-State: AO0yUKWhrLQmEdD5FaRLzeEThtxt6qCNvPunUhGQBmj3WzlON54r5D9R wEtVQAfZu6dA0I0x9idcmv+78PhxGng= X-Received: by 2002:a05:6870:d1c5:b0:16d:f4aa:2c9c with SMTP id b5-20020a056870d1c500b0016df4aa2c9cmr4072490oac.33.1676314667421; Mon, 13 Feb 2023 10:57:47 -0800 (PST) Received: from xps8900.attlocal.net ([2600:1700:2442:6db0:5829:dabf:a50e:e9f2]) by smtp.gmail.com with ESMTPSA id ef15-20020a0568701a8f00b0016df97ab05bsm1654958oab.31.2023.02.13.10.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 10:57:46 -0800 (PST) From: Frank Rowand To: Rob Herring Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] of: do not use "%pOF" printk format on node with refcount of zero Date: Mon, 13 Feb 2023 12:57:00 -0600 Message-Id: <20230213185702.395776-6-frowand.list@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213185702.395776-1-frowand.list@gmail.com> References: <20230213185702.395776-1-frowand.list@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757743440274746547?= X-GMAIL-MSGID: =?utf-8?q?1757743440274746547?= of_node_release() can not use the "%pOF" printk format to report the node name of a node when the node reference count is zero. This is because the formatter device_node_string() calls fwnode_full_name_string() which indirectly calls of_node_get(). Calling of_node_get() on the node with a zero reference count results in a WARNING and stack trace. When the reference count has been decremented to zero, this function is in the subsequent call path which frees memory related to the node. This commit resolves the unittest EXPECT errors that were created in the previous commmit. Signed-off-by: Frank Rowand --- The scripts/dtc/of_unittest_expect summary statistics before this commit: ** EXPECT statistics: ** ** non-zero values expected: ** ** EXPECT found : 50 ** EXPECT_NOT not found : 4 ** ** zero values expected: ** ** EXPECT not found : 0 ** missing EXPECT begin : 5 ** missing EXPECT end : 0 ** ** EXPECT_NOT found : 0 ** missing EXPECT_NOT begin : 0 ** missing EXPECT_NOT end : 0 ** ** unittest FAIL : 0 ** internal error : 0 The scripts/dtc/of_unittest_expect summary statistics after this commit: ** EXPECT statistics: ** ** non-zero values expected: ** ** EXPECT found : 55 ** EXPECT_NOT not found : 4 ** ** zero values expected: ** ** EXPECT not found : 0 ** missing EXPECT begin : 0 ** missing EXPECT end : 0 ** ** EXPECT_NOT found : 0 ** missing EXPECT_NOT begin : 0 ** missing EXPECT_NOT end : 0 ** ** unittest FAIL : 0 ** internal error : 0 drivers/of/dynamic.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index becb80f762c8..dbcbc41f3465 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -329,9 +329,17 @@ void of_node_release(struct kobject *kobj) { struct device_node *node = kobj_to_device_node(kobj); + /* + * can not use '"%pOF", node' in pr_err() calls from this function + * because an of_node_get(node) when refcount is already zero + * will result in an error and a stack dump + */ + /* We should never be releasing nodes that haven't been detached. */ if (!of_node_check_flag(node, OF_DETACHED)) { - pr_err("ERROR: Bad of_node_put() on %pOF\n", node); + + pr_err("ERROR: %s() detected bad of_node_put() on %pOF/%s\n", + __func__, node->parent, node->full_name); /* * of unittests will test this path. Do not print the stack From patchwork Mon Feb 13 18:57:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 56476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2515986wrn; Mon, 13 Feb 2023 10:59:48 -0800 (PST) X-Google-Smtp-Source: AK7set+/iYeQw1Wss5UpxiAsBzKT9vT0nQ3bWhmKBiOE+f6Kee6eptEu3OqDW3R9ZSsqoW56sVCL X-Received: by 2002:a62:1e85:0:b0:5a8:4ba7:583c with SMTP id e127-20020a621e85000000b005a84ba7583cmr14800316pfe.25.1676314788390; Mon, 13 Feb 2023 10:59:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676314788; cv=none; d=google.com; s=arc-20160816; b=XN4qJNUvlYwCrba3axa3Di5Nt7BLbPpDKE4Y+B2vFb4r6wjw1XQoCbf1umsdOqB2j7 bmEhUEzM8VdpeiUGhNM3SZ+pg0BDRdnzPmyDHV1AHWzbh4r7L1SFrNOZf999/vbNqfUr 05t/U7o79LVUICMqao4l2Ua0a8Jc7fAsnjT52n7/KV25jHJCm52YC4h6/WPrBuOTMMrF KTpQey3xKqzOud9/FG2uXccH9WX9yKfuGsHHR3Ss2AZbzmiDDYOaDlavzPngMau71sWu h+MonmldJuop5m3dCwo5lkE7bt4pRtIOiR8rew34VjCNKdOy+s4ORC3B/BHO987GPTnD 6u0A== 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=70NV1ToQYw50ymKhliFnw04sCbSTdpnLCftKunJ8RHg=; b=gxb76/QPhUsJ2t93GLjycS0FVqYpV2nChn3AyBoePfjJr2ny94NsW/Z88q66o6zKUI xwQurvePN3kCBuG+MaX95OfnAR6zZ6scnq9S9gpALDSd/uxfOgaiazPOlBVL8ySTbKfl sX8EIeQD9tvlCDUwDVWczPArCaGnUfGmvKd2F/GMsuBISqyG1wSiKmHH8Mnsh/vBoz6f Kvm2xx/tQErY5XROf0yY39dE4l5bn4qgw7gI7SpW5EiMDPen4Qgk3aA444u6H+NwFceV cGyc0V8R4ZdBBf5OiFqn74BE3cE7EHu06bxerTlZaXP9Mm0NklbkhaJ6GBVcy+O6rhFR uBEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g9sh5Qac; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h15-20020aa796cf000000b00593ea1c4e6bsi5625728pfq.88.2023.02.13.10.59.35; Mon, 13 Feb 2023 10:59:48 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=g9sh5Qac; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbjBMS6I (ORCPT + 99 others); Mon, 13 Feb 2023 13:58:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230315AbjBMS5v (ORCPT ); Mon, 13 Feb 2023 13:57:51 -0500 Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97482212F; Mon, 13 Feb 2023 10:57:48 -0800 (PST) Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-16a7f5b6882so16261904fac.10; Mon, 13 Feb 2023 10:57:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=70NV1ToQYw50ymKhliFnw04sCbSTdpnLCftKunJ8RHg=; b=g9sh5Qacww+llc+gZ856ZATND/GgMxZmJwDrrtBnaKgEjkHC9HhL54iHcxadntNZe4 GRl3VCNHl6m76J0dEebp8wkYjxq796dfRE1az472jTwiWwcTUY4buwcCj59n1ZADxf+y sD+qVetPtACRyLrtREXLIhnjO7Gzk9Rj1ikXBkJL3KKhhoTsvjJIBZYcPqAasR/IJAyP 5mA3P7Eiv4/c8Ty1/S9VKNG/i9nR+9zMfnPyqgGcKqu9cugjiItlBaBVKDQ6xUYwisVK 8tou11iSWFraZ1qBqqshAHKBu0RrdFVSbESIIuDSCWumnjWUuajZz5ZXiVQwQQjVEO9Y GD+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=70NV1ToQYw50ymKhliFnw04sCbSTdpnLCftKunJ8RHg=; b=UEX4beqUh/ySTAoGzvytlBfO/za9kg0fsjApiox0RbOf5ckMCPBblU8g5ReqfgPMIR FFM9BbYq5TlVP/k6U2nGkWwkHolvoM+pG4hpL306dNoH93F6lS6aRI+orsvDWSFmljhY ZexHPyfa+ydsU48vJVOrxQ6sVIBdNi8yLewv0QD5P5EUoShS6ZXpld1ZGMOwlZryG5CZ TNL6rERpenGAW0AlqvjkpIp6l4VdIGs/xRq3+fNXlxFmXJetQRUv4ik1Q42/xlPYfmRZ 3zOQVpR+58oPaFSvGYH3HU0K+fuF7eDzjF2rZ8QoW12jJS6sGPjoKvx7JiLcKNw8IU2o AA3w== X-Gm-Message-State: AO0yUKXNJHIg6tMcoiiOL4tVoEA3XkSTKg5OMh8NmZygcD7U+6YKiIDL N+1ZumBle1v6Bf5zIltpoqc= X-Received: by 2002:a05:6870:c68c:b0:16d:bbce:29d6 with SMTP id cv12-20020a056870c68c00b0016dbbce29d6mr6703085oab.25.1676314668277; Mon, 13 Feb 2023 10:57:48 -0800 (PST) Received: from xps8900.attlocal.net ([2600:1700:2442:6db0:5829:dabf:a50e:e9f2]) by smtp.gmail.com with ESMTPSA id ef15-20020a0568701a8f00b0016df97ab05bsm1654958oab.31.2023.02.13.10.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 10:57:47 -0800 (PST) From: Frank Rowand To: Rob Herring Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/7] of: add consistency check to of_node_release() Date: Mon, 13 Feb 2023 12:57:01 -0600 Message-Id: <20230213185702.395776-7-frowand.list@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213185702.395776-1-frowand.list@gmail.com> References: <20230213185702.395776-1-frowand.list@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757743455883652467?= X-GMAIL-MSGID: =?utf-8?q?1757743455883652467?= Add an additional consistency check to of_node_release(), which is called when the reference count of a devicetree node is decremented to zero. The node's children should have been deleted before the node is deleted so check that no children exist. Signed-off-by: Frank Rowand --- drivers/of/dynamic.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index dbcbc41f3465..657a65006056 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -377,6 +377,10 @@ void of_node_release(struct kobject *kobj) __func__, node); } + if (node->child) + pr_err("ERROR: %s() unexpected children for %pOF/%s\n", + __func__, node->parent, node->full_name); + property_list_free(node->properties); property_list_free(node->deadprops); fwnode_links_purge(of_fwnode_handle(node)); From patchwork Mon Feb 13 18:57:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 56477 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2516308wrn; Mon, 13 Feb 2023 11:00:24 -0800 (PST) X-Google-Smtp-Source: AK7set/B+5xaDynYv+xVaPFn4W3WFtNzf7oj4VjloAJ1MzMMsZuBF1LFvwKr09AWur2wJ04XPIko X-Received: by 2002:a05:6a20:2a07:b0:be:c7e7:7988 with SMTP id e7-20020a056a202a0700b000bec7e77988mr22780116pzh.59.1676314824215; Mon, 13 Feb 2023 11:00:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676314824; cv=none; d=google.com; s=arc-20160816; b=XWyExOoml4CKFnjirt1WvgtWQ3mtuLSvuYVMPC/UtfNosIgPdzLIWTrdtPFEbRAA/v k7gLeK6+dstvlnohphtZkVCUfeEsuLTKbTkqXM0GMji0aOylUJ+x9wrBjKnv29j8IqJW jEtSmyH7M7kuTCBqr0gYrI4z4FHD8DmyJWFHGLXrJbT63t4Hol3Ze9a6kzY2EWBgTyAo c8D06I83LdMdW2GeyzJkyZQ8X/R1b//R5GBZqPZm9qtcXElS9UOtDSmptxYqAUwNhB0f ByUghzm2K68cvpF9hI1mHYSci83xas/QhaMD7TvJEHsNSe+GcVsl001wSgyfjeuh26FL Zxag== 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=ZhoQvg3BMaFTkvvFqgv6WpxCoYJyC9DRYUszslZVGiQ=; b=N96NLHryHWB9ey9YDN55v1EWg5ycR03QJFzNocuqjllsWWgSAQTf2OqEeHFbfKwMMc C8gAoKY+eEraE9X4222cdHin85U+apMjNeqmRVic7+5jaIPX9azOH2cE3f8lN0I7Zhsy dMpvdCgYfLA8VTBXag/hmI0Rotp4e0z1+HTejnFR8ksd6Yh+ieew8uzOHu9JkK78xxgl 06rrTX4i03ii4rY2YPyY4jweJ7MJTzJAodVL9wcXDJ1gxDvk0wKVf4e1Kb5AcBVmAik+ lWyoxcWakac6xaKjymzQjSObtCZAG3z7Wj1/8OBW2GQZG6uZa1oZ9Anny74x1lHSzA8U vpPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="FXWPwOo/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 133-20020a63028b000000b004fb7d5d316esi7617453pgc.404.2023.02.13.11.00.11; Mon, 13 Feb 2023 11:00:24 -0800 (PST) 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=@gmail.com header.s=20210112 header.b="FXWPwOo/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230478AbjBMS6L (ORCPT + 99 others); Mon, 13 Feb 2023 13:58:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbjBMS5x (ORCPT ); Mon, 13 Feb 2023 13:57:53 -0500 Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C970E76A9; Mon, 13 Feb 2023 10:57:49 -0800 (PST) Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-15fe106c7c7so16264809fac.8; Mon, 13 Feb 2023 10:57:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZhoQvg3BMaFTkvvFqgv6WpxCoYJyC9DRYUszslZVGiQ=; b=FXWPwOo/Ee+i5OIz6j2njqn0ZzUk6+WwUfHqMu0bXnatgSmwQmHnG+Iqvs4fG8bE2l qn3stmEtWIHTu7T53g0gyk86US2YfreUbGwa6bH6cqO4zTtCFZMf1THvRYLwSNe0sGI0 CF1t/wP24ReLd6zmr/VQsWnppeI1WgQ5A9ZCh7+M+ZkaeMk3A7eWDK0+w8kPFYi1rxfW G5GVxZnhOrqahcj6G3zNy329jhG3W2RQqqlyVGLSwymtjNRBuAfpyE7/9tAUlPoOFi3s WLDmHZCWop11hftaciL9juMEqbn0z7lf8dtpDQdmQJpjSc9S0fOF03rya70VD/iK6M70 2yPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZhoQvg3BMaFTkvvFqgv6WpxCoYJyC9DRYUszslZVGiQ=; b=CZcFdh5JkOC3GZgEFLJlE20W00bKIbVf3E+SxIQvfPoLzZofZjwBgG+gyGPvl+Nm62 Wl6UynFs3Bq2nEf6b8gRwzFm3tOPYO7l7ZbyGRgH0n4ga6Qlgw1qegCqX7x8wYOmyEeP k6Oooi9XgsB3VMUnzP0OF1pkDLDgjtEHjRaXlHVo7A2nVZvgnNjUJCoVkM0R5zwW72wB l22cAocXvacTmsTJRKILuPXDgdtrRgcaep/U+rLs7L3hmyChIBjXOgDeWNbl9uE/uVXx OmuGPva6lnrwR5FwmedlBPoCjhF1qLFnRwmR0GO1o4HtOOlHkk2IwWHlJfJRRZK756mk kTNg== X-Gm-Message-State: AO0yUKVxeM47QUOMsSootrUMgYacor/shmOu4/FBj6XKnhHxHsTXhwKt 0m+ut4R92biqJK9jpHSx2n0= X-Received: by 2002:a05:6870:d69d:b0:16a:c8ed:f405 with SMTP id z29-20020a056870d69d00b0016ac8edf405mr8255809oap.52.1676314669212; Mon, 13 Feb 2023 10:57:49 -0800 (PST) Received: from xps8900.attlocal.net ([2600:1700:2442:6db0:5829:dabf:a50e:e9f2]) by smtp.gmail.com with ESMTPSA id ef15-20020a0568701a8f00b0016df97ab05bsm1654958oab.31.2023.02.13.10.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 10:57:48 -0800 (PST) From: Frank Rowand To: Rob Herring Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/7] of: dynamic: add lifecycle docbook info to node creation functions Date: Mon, 13 Feb 2023 12:57:02 -0600 Message-Id: <20230213185702.395776-8-frowand.list@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213185702.395776-1-frowand.list@gmail.com> References: <20230213185702.395776-1-frowand.list@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757743493370544394?= X-GMAIL-MSGID: =?utf-8?q?1757743493370544394?= The existing docbook comments for the functions related to creating a devicetree node do not explain the reference count of a newly created node, how decrementing the reference count to zero will free the associated memory, and the caller's responsibility to call of_node_put() on the node. Explain what happens when the reference count is decremented to zero. Signed-off-by: Frank Rowand --- drivers/of/dynamic.c | 3 ++- include/linux/of.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 657a65006056..12aa99018969 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -443,7 +443,8 @@ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags) * another node. The node data are dynamically allocated and all the node * flags have the OF_DYNAMIC & OF_DETACHED bits set. * - * Return: The newly allocated node or NULL on out of memory error. + * Return: The newly allocated node or NULL on out of memory error. Use + * of_node_put() on it when done to free the memory allocated for it. */ struct device_node *__of_node_dup(const struct device_node *np, const char *full_name) diff --git a/include/linux/of.h b/include/linux/of.h index 8b9f94386dc3..e20a08c8a8c8 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -100,6 +100,17 @@ struct of_reconfig_data { struct property *old_prop; }; +/** + * of_node_init - initialize a devicetree node + * @node: Pointer to device node that has been created by kzalloc() + * @phandle_name: Name of property holding a phandle value + * + * On return the device_node refcount is set to one. Use of_node_put() + * on @node when done to free the memory allocated for it. If the node + * is NOT a dynamic node the memory will not be freed. The decision of + * whether to free the memory will be done by node->release(), which is + * of_node_release(). + */ /* initialize a node */ extern struct kobj_type of_node_ktype; extern const struct fwnode_operations of_fwnode_ops;