Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1543882imm; Fri, 12 Oct 2018 21:57:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV60ChO7yJ3iaKjyqNZjMVP9yQqHfdfrNn71Pp5k86L2bxrK/c3MvHMoEqksuzgwtHhI413xx X-Received: by 2002:a17:902:5a8b:: with SMTP id r11-v6mr8778094pli.305.1539406657985; Fri, 12 Oct 2018 21:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539406657; cv=none; d=google.com; s=arc-20160816; b=tOhA34e1AyuKFMhg2dbqpSr9zUjmpiF0ot5yXR2Aok9kusA2WO238+t3cNA60a1oV0 U2K/CTILSki/KzPWDdLgNSRY+Bb9Y4k2F8OdEo15MWTD883RBikTUpl2PiA6txMDUfrL DX+s32f51rzF2pr1Cksz/Vh1FcaH78oqw5//QZfxBnEW9wOc/5A+Yn5fxyKrcpi8yzEJ NDMFFlqtoNTeVoOHTMLhdbTFMJrWcNdL9Jg3vbmIg0OfWfrgs36O9uLVYOXFhhohgQcd GA8T4bLvBdL9/xqcR/Bv5cI/YLio57CzaGqGtbvMNWKGdSIOawFaQovqGJWI8NQLwVgQ C1lQ== 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=c4g80DvyuudoX+LPD+xlMBYx8TzUWy649W9bh+/3Apk=; b=fQXiOkVsLq++jyNJzFNmMu5JhPhzItyQ2eU7qkgn3b/s/KOhw0RTqtifOlhfQSimxs Mw2wxuaEjNjIdJMUI2h0gNPsLAyeoUNspFCce+jLKqv3swoo8WGJCy70U8eB+/sP+8nH l0ZgcLasRFh7TLe42PHT0mSw6W/yGucVcDRj9f9C457WWGgqMBTiqhJ4mKe88StKk+6S rA5L5ZvP/LbFMpmIHxXtaVSdyrhuM944F5Yu7OV1K0pA4+IDFVo03/XrMrhbGGLfhue5 kpUCg92Xmk+4/ChEFuYR91/k2Hy8yphGH2+M5y7emgopHME1oXOiXsTyiHd7IFw5C171 qckA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EBE0enLF; 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 a5-v6si3421286plh.312.2018.10.12.21.57.23; Fri, 12 Oct 2018 21:57:37 -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=EBE0enLF; 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 S1727285AbeJMMbT (ORCPT + 99 others); Sat, 13 Oct 2018 08:31:19 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38627 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727195AbeJMMbI (ORCPT ); Sat, 13 Oct 2018 08:31:08 -0400 Received: by mail-pf1-f196.google.com with SMTP id f29-v6so7166015pff.5; Fri, 12 Oct 2018 21:55:28 -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=c4g80DvyuudoX+LPD+xlMBYx8TzUWy649W9bh+/3Apk=; b=EBE0enLFfZS00Q4vrKlNiFa455XytYgOWZqS/oM4Ln9QGgwPT/7BO13cvxIOpS/czO jBq/WJJoqKV3FDKdOsuk2RKrPh+jn9AbcxrBExEQFwEmUYWtnFQzBNjFHGwMH2i9j4IH hgeVskYmNiL5O7ayDrweoVr0Jb5VkNBwJjzl3u6H1b1YmX1P5pfPs48SV8beLyvcj2ex ijwDIm7+ruP8bA/mMsmmuvhm8ci47KyEdW8pgrMw0nU1btPZ5u7hhl4ZK9qs2vRLHvsP /aJxslL8DLNitvpH45H/jpRAOpLsNufpKrsBMnxyLZfycpJ3s6vjTDZwNhCGz45bTq4L gJbA== 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=c4g80DvyuudoX+LPD+xlMBYx8TzUWy649W9bh+/3Apk=; b=A+RnhOEEYLjSWxqufAQ3gpfGmxhdHtIp4pRdH8LQ5Xro98dMY6OYX8N7mJLCwQACyZ /3dV1MLrBCvvnFWL2YZi01OKpJmLPb/gSw/xpieA1dOP/gj2t5oF1RDdHdndIyCls1P+ 0+LMB86Hw4t0YwNgKRgqjt5cEBcKU/ENzb+z/mdo3JAESQWdnb5PHuXRL1vyCRdfZxiX ewms19ca3EvlBWjXVY+Fx+5RTst/7TlgS4Yx1kyqXXxSW7BEDIqi1D181YLdOISPKfpq DXAXN+0pTrW794Y57nUFFRCj1ORhS8/8ulCU+qcuVt1kARdmR1mEUBmyV2V07Q/xm4aX r3hQ== X-Gm-Message-State: ABuFfoih6SAprG4bC8rfZPFIzdxECajB8Hg9F0kFN5ljNo4Xy7URch0c 6vSgihJX5kcIuwNpeErHMXQ= X-Received: by 2002:a65:528b:: with SMTP id y11-v6mr8134116pgp.269.1539406527279; Fri, 12 Oct 2018 21:55:27 -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 h87-v6sm6959462pfj.78.2018.10.12.21.55.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:26 -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 v2 18/18] of: unittest: initialize args before calling of_*parse_*() Date: Fri, 12 Oct 2018 21:53:38 -0700 Message-Id: <1539406418-18162-19-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-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 --- changes since v1: - add same fix for of_parse_phandle_with_args() - add same fix for of_parse_phandle_with_args_map() 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