Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3323025imm; Sun, 14 Oct 2018 17:29:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV625WWIXNQNHC5/Z87kSKQXiKXgAt+BIWQPh+cfLKAnBVhNDy3Oojv25aW5yXj1RAMCbxdHy X-Received: by 2002:a17:902:44:: with SMTP id 62-v6mr14972452pla.181.1539563349386; Sun, 14 Oct 2018 17:29:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539563349; cv=none; d=google.com; s=arc-20160816; b=xT3SspCxsmYX+CVnfeO1Vcp+c5lu9/jBwSDxFBtl3P6NSasy9UVqMqReek1dxcg7lw AhtuC8xWPiOhBr2yZPG2Ft2ozUk/7tRkHrIEIK9Kon3m3nSf/S4w4gw2yDEPxyuSmO3X Ki6qLl6I+vgr3wwNJ6Vd5gnue0D38VMRWytkZNh5p72fcQbzQexBt8ixYAMjPBuf0z08 SxJbuDkg1ihcA8ijknF8vjy7ue0wBxioVgjQ7vlT58GFVFHOkBlqcPTmwiH2uPa9C5r5 97vpjmn/U7cyo4Ieaz+duGRCsQdoubuwv51rWo8DzDpp/4cezi75lEbv/wZL7gdwfwp2 I7sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Q0blMRhqNPiCrzvXWEp+FPb/ePWbrdIXRWW/hT0vdeE=; b=HBldhMZA4HoR1FFVio3jeVI9K2cMeWSsMq3yX5okngqoJ8zbWusj6T8XqIM9XB8CPW Ixof/89sBKQcYFrYe+IRODBZGblmE0kR6u45NqY3NA+SBcdVy9SvqWG4i61RevalQESC fRZjsX4L1e/p7Htgjti5lyShZs5J2hhb1x92CePLUGdPdyVoBRZ0qdX6PgMG+tMZgmJi HIXLjPo8v+kW78zLpNWdXomURjMkNYmYGC8Vj26M9UExlk3gZXjDZtoJDe2I9kY1ZU38 OR48v/0zrgWbeKsKkoaNuT6JwCIEgtplH3PJ7bASfuTIVpOQxLaUubU653bDiufgCPXA TwIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Rpnfi/Yt"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k70-v6si8505167pgd.2.2018.10.14.17.28.55; Sun, 14 Oct 2018 17:29:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Rpnfi/Yt"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727018AbeJOIJM (ORCPT + 99 others); Mon, 15 Oct 2018 04:09:12 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36259 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726979AbeJOIJK (ORCPT ); Mon, 15 Oct 2018 04:09:10 -0400 Received: by mail-pg1-f195.google.com with SMTP id f18-v6so8309144pgv.3; Sun, 14 Oct 2018 17:26:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q0blMRhqNPiCrzvXWEp+FPb/ePWbrdIXRWW/hT0vdeE=; b=Rpnfi/YthBio9UGW3cAii3/UHa+crCMwoFN5Oto2G1OkPcu8ysLW+KK/4QpUsopwRv Lnz9ziL806pO0q7YNFw7EbgGUFsl4DG4O7xUb/r9eZwLq6ETJQ6rrPtFGKvnV+1qXNv8 2bUhTR6vKfo5AVq9NSIIcNk1BFn/HMNsq3dpG8etwwVDmobqZLekiwfY4O6CjzjomhcR M4w2Tm1iz65XZv1N7sqDa1jJTQ7lyXMBcPerQF7TXakdAjxOuSet8NMRenJ8Tgs6gnzE vnQm4aeXzQ1opWNem9ObFAV2NqevDdeq7zLHy8+Wk5LD7wwJ4KbyzbndRJyVWBjBRc0b 9XJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q0blMRhqNPiCrzvXWEp+FPb/ePWbrdIXRWW/hT0vdeE=; b=Cw6eExYT6hBPSH9AeKzuLiHSnc8tQW3s0jYakKFWYva0cf7WwrL1q5dSf1q8r8oToU zsSK6WvZcJzbizPY5deLPG6xLJ0I4/BNDULglqO1qxqFykDq8dDudDAjvkBWThqfFhCw t/kVjxWyWYgURNfEmccFX2LWRvI7i9Ljl52d4O5qakJTFOk/FE3gW0+n8qbtfqMmacun beTEKzXiaZhwPrHvFXqDRyo/y9FbY/c50I7N4vMN2CQrNZlkIBaigxi3uOxLOVowD8a2 SKCksZKF/cCUBturw7cvWxV7N5f9e5Ey7rgz7HwuDfQtW39je0352EwkBmhVx12ronWV 5N0w== X-Gm-Message-State: ABuFfogN9rQp0m7CHSBBmscDfRmTNfM/U/QaO2DmDb0aPPVV79MswLiE OrV74yWcXcQJV44xb2AhqyI= X-Received: by 2002:a63:e04d:: with SMTP id n13-v6mr14238400pgj.426.1539563182425; Sun, 14 Oct 2018 17:26:22 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id j14-v6sm11387110pgh.52.2018.10.14.17.26.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 14 Oct 2018 17:26:21 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer , Guenter Roeck Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v3 18/18] of: unittest: initialize args before calling of_*parse_*() Date: Sun, 14 Oct 2018 17:24:30 -0700 Message-Id: <1539563070-12969-19-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539563070-12969-1-git-send-email-frowand.list@gmail.com> References: <1539563070-12969-1-git-send-email-frowand.list@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Frank Rowand Callers of of_irq_parse_one() blindly use the pointer args.np without checking whether of_irq_parse_one() had an error and thus did not set the value of args.np. Initialize args to zero so that using the format "%pOF" to show the value of args.np will show "(null)" when of_irq_parse_one() has an error. This prevents the dereference of a random value. Make the same fix for callers of of_parse_phandle_with_args() and of_parse_phandle_with_args_map(). Reported-by: Guenter Roeck Signed-off-by: Frank Rowand --- drivers/of/unittest.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 785985bdbfa6..5f4db23e4752 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -375,6 +375,7 @@ static void __init of_unittest_parse_phandle_with_args(void) for (i = 0; i < 8; i++) { bool passed = true; + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args(np, "phandle-list", "#phandle-cells", i, &args); @@ -428,6 +429,7 @@ static void __init of_unittest_parse_phandle_with_args(void) } /* Check for missing list property */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args(np, "phandle-list-missing", "#phandle-cells", 0, &args); unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); @@ -436,6 +438,7 @@ static void __init of_unittest_parse_phandle_with_args(void) unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); /* Check for missing cells property */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args(np, "phandle-list", "#phandle-cells-missing", 0, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); @@ -444,6 +447,7 @@ static void __init of_unittest_parse_phandle_with_args(void) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); /* Check for bad phandle in list */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle", "#phandle-cells", 0, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); @@ -452,6 +456,7 @@ static void __init of_unittest_parse_phandle_with_args(void) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); /* Check for incorrectly formed argument list */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args(np, "phandle-list-bad-args", "#phandle-cells", 1, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); @@ -502,6 +507,7 @@ static void __init of_unittest_parse_phandle_with_args_map(void) for (i = 0; i < 8; i++) { bool passed = true; + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args_map(np, "phandle-list", "phandle", i, &args); @@ -559,21 +565,25 @@ static void __init of_unittest_parse_phandle_with_args_map(void) } /* Check for missing list property */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args_map(np, "phandle-list-missing", "phandle", 0, &args); unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); /* Check for missing cells,map,mask property */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args_map(np, "phandle-list", "phandle-missing", 0, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); /* Check for bad phandle in list */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle", "phandle", 0, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); /* Check for incorrectly formed argument list */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args", "phandle", 1, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); @@ -780,7 +790,7 @@ static void __init of_unittest_parse_interrupts(void) for (i = 0; i < 4; i++) { bool passed = true; - args.args_count = 0; + memset(&args, 0, sizeof(args)); rc = of_irq_parse_one(np, i, &args); passed &= !rc; @@ -801,7 +811,7 @@ static void __init of_unittest_parse_interrupts(void) for (i = 0; i < 4; i++) { bool passed = true; - args.args_count = 0; + memset(&args, 0, sizeof(args)); rc = of_irq_parse_one(np, i, &args); /* Test the values from tests-phandle.dtsi */ @@ -854,6 +864,7 @@ static void __init of_unittest_parse_interrupts_extended(void) for (i = 0; i < 7; i++) { bool passed = true; + memset(&args, 0, sizeof(args)); rc = of_irq_parse_one(np, i, &args); /* Test the values from tests-phandle.dtsi */ -- Frank Rowand