Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp698821imu; Mon, 5 Nov 2018 07:29:42 -0800 (PST) X-Google-Smtp-Source: AJdET5fAEjKFGG0sDe2w4YqWJwdGx67B7o7bheyN5jNYQwGwcmogFeydIXQzvfmrXfmC2lAicBDe X-Received: by 2002:a17:902:bd0a:: with SMTP id p10-v6mr21825653pls.245.1541431782729; Mon, 05 Nov 2018 07:29:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541431782; cv=none; d=google.com; s=arc-20160816; b=lYjSWHlq0OOa9ZcuIB9pr80h62/kb494bj5ov6ubQSyATkvi6WZtSfqQCa2iUj3+iN uNAdZULmI6m02mOA0CQBM9PzZ3sgovmLoNmS6EEPwQHLbpfmRGP1HjxZqSD159vF0+IV ikRqmHxoXYrJQFoD6PWbsoECKWCMFa41E1iKDdGm3ma4GEmEWUt1R+JzMJ0jDSwauuqw BnfS7Mc9fcIsa5dQdDEnyz4zjEqVVx16UFAPkeX53tIPv9cNFcWLSkaHPAQbploG0Orf vc2bidNvbPzVNkZWiGoB9r2hg2ADDbRi5c4br40WZCsiC4Lu/sIuJ0fn6+WP+1MQxHL8 0eTg== 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=cW/aLXOwyBpDyXo/7JT8z7O8HOv4Q66hATfzdpFXsv0=; b=KoxCgyKxlTf70r35ju1Bm79IdplOx/ig3rYWjHqhhk/2eUuIDRiNa1lozvmPJLIlSi TzEM/MWwK4YAvRd/o5Z0951gbNOncAYSvKwZRwIfGGGSecrTU/6VDJrl5wZblqv/Hkie QR2h1k19VWc8LPZTwHZYf3E6MYJbujV7a1wxGqFRRpORqhkEZ1Pi0iA94+uCx26XvmQw 46r/hHTqn+EZaTiLobqBUivDzl8oseYYxU38BPsT3d5coamyqzpCUhX5LuC8GcbFysfK eJluMWm/G2bToaOsFb0iNb6tA+Q0jJKzoKJFMLmbIesUaHRfPNhbZKKVbjS6UrbuYByK ytDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uamofHmW; 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 f7-v6si33886476plb.362.2018.11.05.07.29.26; Mon, 05 Nov 2018 07:29:42 -0800 (PST) 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=uamofHmW; 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 S2387578AbeKFArb (ORCPT + 99 others); Mon, 5 Nov 2018 19:47:31 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:33271 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387533AbeKFAra (ORCPT ); Mon, 5 Nov 2018 19:47:30 -0500 Received: by mail-pf1-f193.google.com with SMTP id v68-v6so1001164pfk.0; Mon, 05 Nov 2018 07:27:16 -0800 (PST) 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=cW/aLXOwyBpDyXo/7JT8z7O8HOv4Q66hATfzdpFXsv0=; b=uamofHmWNylMh9AfrLZbXcwVesy8gBT09C83yN00T0hu1uHopBeJI/snX+FgeCIx6e Iryt/e6JxxCjc3Ga88XaClGcAxAUpvOvQ7qvZu8EMnuk4QyqA8uOSLFJA17cZnA1Fmhq hn8LJDoiossYyVvpv417pxS9r6AsiqhOGx2qa3aCp1jZHPRnQFsWM55UnQcsu0nN91rf gDyAdumjlZaKSI9E4f0Qol0JhBKFr1XAt2K07+7sHxISkXF2SJi3OS5qZIi2gzvu5pS0 XHCiemHo7LN3htyuVe8OYfcp+ZKHh/VrxbxIGjq5SJjkqdE/CZdBpIhTeqDpTpNiv3du N26A== 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=cW/aLXOwyBpDyXo/7JT8z7O8HOv4Q66hATfzdpFXsv0=; b=MUzWWcY4zrAu3q0KTYEx8zsg/yFZELaPsOUL5Cv8b6s1oQcYyBbudN8q36ealdkCoC wcRKTDyO4nyDQaWAq718SPciCaFiCURBwgM+5JOdHt2G8f+wH3Lqj4gCIsXJ2teQgR35 vtKWCfV7rfQyTeg8k3QktaHk4KiGEif/BMjos4MCwI8I44eY/SLGaL5J63tqYsJwKNa5 JMOl3Ptx4r6kQtvqVWsIJVrVfaXHqf0T0Z6hL+05qaz4ANDU3dYV6q4UFvoF4tvA/DEF bRghUoSerzhZuj/nUHovY+9OP9cWsai3CJWSluLyExYKLgi5AwtYlCkd7MR4zmw8NyK3 +K4g== X-Gm-Message-State: AGRZ1gIJnB6MJCNGbkiR9oA489obHFcOxahfKcguY+un+ftmmvigOIvw N4KkHA1jU02DWUxVaFMQxaU= X-Received: by 2002:a63:4745:: with SMTP id w5mr20971062pgk.377.1541431636362; Mon, 05 Nov 2018 07:27:16 -0800 (PST) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id u76-v6sm37260578pfa.176.2018.11.05.07.27.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Nov 2018 07:27:15 -0800 (PST) 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 v6 18/18] of: unittest: initialize args before calling of_*parse_*() Date: Mon, 5 Nov 2018 07:25:15 -0800 Message-Id: <1541431515-25197-19-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1541431515-25197-1-git-send-email-frowand.list@gmail.com> References: <1541431515-25197-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 Tested-by: Alan Tull 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 fe01c5869b0f..9a10a48eb6a1 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -379,6 +379,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); @@ -432,6 +433,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); @@ -440,6 +442,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); @@ -448,6 +451,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); @@ -456,6 +460,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); @@ -506,6 +511,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); @@ -563,21 +569,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); @@ -787,7 +797,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; @@ -808,7 +818,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 */ @@ -864,6 +874,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