Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6000584ybc; Wed, 27 Nov 2019 13:10:56 -0800 (PST) X-Google-Smtp-Source: APXvYqx2PClXbxxAzGUq1sTNEEnj7ndB32kdiAyGSITusHpflNxTWXBFMU17PY0BFjpqGNbJh867 X-Received: by 2002:aa7:dd4f:: with SMTP id o15mr34137736edw.189.1574889056636; Wed, 27 Nov 2019 13:10:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574889056; cv=none; d=google.com; s=arc-20160816; b=cQUKRSoDlgD2q4/PuJXJQbSOpEhzoq3q6nxpXi7xHLMvpe7lvuwD0CRv5XVSdxyj6p jizezJWD+oxicOvZRLsPNWl6VUtP+F611bvGhgniJuiDak2wa8RCeBtUuJk2nte97Mlk w+llsVBSLhawd5Qk535DAa0roQ/uLBUN+rMgSNZLkxeCC8s+e6rZIuYGQ5TeP/1Ig67f nen7VDECkrbjZ371paSXHwHvXy5nMU2DKo9GTn56gOk4DCZNQWcEEzPI8ZWgZyX/w/u5 UFZdLjXERpFiLYjjvutwguZrw0gfcq/UEEKLCsBio/1tWER43Mr2qsx+6ov9AQI/5tHR TckQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vB3+50UnheP+KpfTG/5RHt2KMJWm0+W+Q076zdawGYc=; b=LyrejmJV2OWE4QlZ0GQisqn+/VqfLPlBGjChYsC9nzdMfVQVI1COyKTR8GlJF0iZMX V/J865vdugpalPmi/3cZk24qRtObo4mgbbugDvecWnTqkXqsK/LSZXzANzlQCzZcwiDc 6agsEGcs2H/JebuT2Y86XMXvo0oLrk1k/wnUdpSwZIoG1YNSRXesMVVrtLO6FxjzOoi6 7+eCnaEyzN/sAG8IV43RemEUrAxeTjkX7zkOd/Ok3pA2zT/dZfLkHDXj9acx4LuqZaIy 5W6lXqsY3PQyaX0IdunKi9lY58lxeYeiKs/dxqekFG1xNkcKtZD4l8odzx9CKuuvc6T8 Vjvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EFImgv6o; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h8si10103229edr.138.2019.11.27.13.10.32; Wed, 27 Nov 2019 13:10:56 -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=@kernel.org header.s=default header.b=EFImgv6o; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732545AbfK0VHE (ORCPT + 99 others); Wed, 27 Nov 2019 16:07:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:33120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732190AbfK0VHD (ORCPT ); Wed, 27 Nov 2019 16:07:03 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 298992086A; Wed, 27 Nov 2019 21:07:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888822; bh=O4jI/UD5cwgEfztd/WN3i8vXnYRkU/s8BThrOIUqah0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EFImgv6o1bKix28RjXqsghY2jDFhnWAoBCKK2ao+KCUIHj0LwVTB7yPm2mtAhVWBe jY2byUPdeHqbAyy7k0nEKSDK4kc2d2s09WPXdUKy/H3wB0MSJplsgyh9jihHvSuCOG nqFVKtxXD3dcD31pLZzpszju05NvhKxEyEnkWG7I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guenter Roeck , Alan Tull , Frank Rowand , Sasha Levin Subject: [PATCH 4.19 241/306] of: unittest: initialize args before calling of_*parse_*() Date: Wed, 27 Nov 2019 21:31:31 +0100 Message-Id: <20191127203132.576575032@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Frank Rowand [ Upstream commit eeb07c573ec307c53fe2f6ac6d8d11c261f64006 ] 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 Signed-off-by: Sasha Levin --- 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 e8997cdb228cb..68f52966bbc04 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); @@ -783,7 +793,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; @@ -804,7 +814,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 */ @@ -860,6 +870,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 */ -- 2.20.1