Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2489164imm; Thu, 18 Oct 2018 15:50:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV61X8a8tdG3H0xdKm9eZOrz+Eyo56lMiFQmpyngG6ytpHr4K96S79pPqM2LW5vT0GZeI3F0y X-Received: by 2002:a62:13cb:: with SMTP id 72-v6mr31676349pft.34.1539903019542; Thu, 18 Oct 2018 15:50:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539903019; cv=none; d=google.com; s=arc-20160816; b=f4xCJG2L5/QilgrnWNH2slZ0oH/Ij+cr2nurSynVoJIDAa6wAmZkx3AnFawlSXJytz ccXWzzTsffnUAO59kFRAIG59Z2Cz+GjVTfs3GiYVBmHVBEFzN20IzMbq3b4zgdbakJ8T 9RdbxsLfiUbzQ/rfNW59rgeF3fDLpJNsPPIqYjvU+3avm9hEPGqDwfz8qQWt6tvnTdzg agTBsMquERZuPxULr1BIccJTnW0KGQlTp54JJYR/GEMjcDkNFVCryCHSKJ130iMCfG4l JfTYTw/x6tKq/ph3MjAUJ/JvCQ3XrOPCclAAkB7j1DAv6wHx553UWiQAVockic2zfD4X 99HQ== 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=XbVA0FnECA8C5oqBoA2zgKoW/kn16IoAnbprduhu3evn9VyCirYpz9jVs2dhykgejc 9I4kvPqP/m+r1PFTdwuIHITBHNFis8a4gz4/0j9pNFajpvIq3+onxOR2mDMRMjXjS2m4 BQLF70DtrIHEvOtPoxKvEiu/HyJjHjPO7RHExWH3/1POqLjRArd2PrwmprDJMqnvNfOv Al084lGShvbXwMaRpOncqXKrzPGO0W0MgwuOCL/jpZQJKmWeiufK+nZN1iqlkIa8Q8CW FwnbNdN56jaZpgeEJQxMO6vbJYk9SDc+Z+dJpEmUdCU/bWZRSKwyqcg1HgyxRHrXEOPY A82A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bS42HXUe; 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 r1-v6si21610370plo.165.2018.10.18.15.50.04; Thu, 18 Oct 2018 15:50:19 -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=bS42HXUe; 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 S1727769AbeJSGvg (ORCPT + 99 others); Fri, 19 Oct 2018 02:51:36 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:34790 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727740AbeJSGvf (ORCPT ); Fri, 19 Oct 2018 02:51:35 -0400 Received: by mail-pl1-f196.google.com with SMTP id f18-v6so14973068plr.1; Thu, 18 Oct 2018 15:48:26 -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=bS42HXUezmRWOh8roQa+wEPw6WPzcKdYOato/jsp11VbhXCEB2SkyjtGKTOicK/VSL rIZS5H19AJagbC7r7oqWfgXfjibdGSzvMCQ45ATpYJacPgehvE+iOaBQehMSgT44DOSx LLDgDTy1BnYE5BxAig3Wghckm4PoMsMDExZiDYB0GcG6Q5rVX7ArS8wK/1PiOu7O7dr/ bFTviyYKBFinVZbTBVkc/KajKLn9+iDsoJWWG8WfPur7XGynf0BvvxRLBQUrET02Rmvr QRP8wmLMlvkH0Xa30yafQJ6u4cWL+uKSmLP1xUvguQfV4dazlOS7H3ecLb0lnQpgO0aU sJjA== 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=RfZLM3ywcZ+JlJkYs1PB5EnNAlaT49+a43nsBLAFOZ4ihZ2qJT4s3xNVn7mMw9iGXV B6KRBH0wgaE2a3YWtkVDZpzSDu0qdJOAYyzS+D3xrbUdcjOYJACvDBWhrhdd8lw9oZfe laZ01gfwhVSRYGQbxVx62hvxuDBMbXCeqPZZHBOIV47hTkBEVbJFwdZ3hsWGXOOFCCkD uG2ZEzKH7oH9NSY7nj8kDBU4PNPbFYKZn+xtjB9dfGepttVty9qpyOkGQcwqwXU2v/mB eSXyrplVrhNtx03PTzeKXVp/z0pReSK+1qiknruI5s+MQs4c2xM2IMjYy6WSkjJL2GdZ A7Cw== X-Gm-Message-State: ABuFfoiio2Ao/0QTKL0ewSrM/9Y7A0uys2CT9Evd5mKNO4SKkFTuacG3 Qn5x9IhQ38Yxdze3O7FlUhU= X-Received: by 2002:a17:902:7613:: with SMTP id k19-v6mr566453pll.98.1539902905750; Thu, 18 Oct 2018 15:48:25 -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 v81-v6sm38129268pfj.25.2018.10.18.15.48.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Oct 2018 15:48:25 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v5 18/18] of: unittest: initialize args before calling of_*parse_*() Date: Thu, 18 Oct 2018 15:46:36 -0700 Message-Id: <1539902796-8382-19-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539902796-8382-1-git-send-email-frowand.list@gmail.com> References: <1539902796-8382-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