Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1213186imu; Wed, 16 Jan 2019 14:57:26 -0800 (PST) X-Google-Smtp-Source: ALg8bN7Pd/zBoPWcaHXrkcEw4Cf1j/nBoLjKqMHeB+upKWeu3wXXtMldTE4ZeTYWU1aSUR8PBGqU X-Received: by 2002:a62:16d6:: with SMTP id 205mr12231999pfw.256.1547679446515; Wed, 16 Jan 2019 14:57:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547679446; cv=none; d=google.com; s=arc-20160816; b=e1V9NrD0Y+1A5kgsWwRZ3IfWqHN1G4OfGrAHFsJujVmpEhkyBbew8RZrQpuC9QnU4I tAoQU7NPG9Yoc4cOn9BSmIj5ZizzTrTWy81yVMzpxiG+ieDojC9TIH8/lvPnh5FSMBHK LlwNkogiZOwgOrMf8x1yFbTJujF4ROF6aI3kqPfCiHLPdriaS6mNMwPGf675hvILyvQb ESU7PfHqw7NjNc+GZpe8CD1oZjIRav2hdhx5ccorJMhv/cnM79zbBMpl/refTOtBcbdZ 6fCmYtEeglzpQbmpHB2mNxYkTsTNSqXF+M0jUtHjPH2vcz9ocmSj8OSE5U4WX8Hnyf5j MTqg== 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; bh=ftilzXgggygtpGYD3Zi9m93dNtsQhU3Dy0OpvUL2TmM=; b=sbnvaA1AtQcWKRFb1lxkIWuhPc2K8WAOhCbffkAMRbTJ/ZNadUvQYKrz7cCSjsoMAq blsd2GJuLrglPR9/84KxxVy3Tos52MEuQ8cwM7Wa/oWqN73Tu3/Abb71/DL5ZtA2hmOQ tL3PNjA3XG9RV9CWwuDIKlTm+z5Rw1NZ8Y3eqpbvdTN5H15cbQK2FpxbxwW1doOnMJfI eE1Jmf7EN5Bjg3PzgCbSDbNqDs8G6+o2MyKqP3bqmw+I2oWTqhxiuqqELeFH5updrWrt MAC67Q/e3P6r+6JJAnrSe3/vC7AemlGa61nBhXCGDc/hL6PGO+joh8YABM47Y8G5yKky WJuQ== ARC-Authentication-Results: i=1; mx.google.com; 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 d37si7730672plb.140.2019.01.16.14.57.08; Wed, 16 Jan 2019 14:57:26 -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; 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 S2405337AbfAPQRt (ORCPT + 99 others); Wed, 16 Jan 2019 11:17:49 -0500 Received: from mx2.suse.de ([195.135.220.15]:38680 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729517AbfAPQRs (ORCPT ); Wed, 16 Jan 2019 11:17:48 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BECC4AEB1; Wed, 16 Jan 2019 16:17:46 +0000 (UTC) From: Petr Mladek To: Jiri Kosina , Josh Poimboeuf , Miroslav Benes Cc: Jason Baron , Joe Lawrence , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH 2/4] livepatch: Handle failing allocation of shadow variables in the selftest Date: Wed, 16 Jan 2019 17:17:18 +0100 Message-Id: <20190116161720.796-3-pmladek@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20190116161720.796-1-pmladek@suse.com> References: <20190116161720.796-1-pmladek@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Do not dereference pointers to the shadow variables when either klp_shadow_alloc() or klp_shadow_get() fail. There is no need to check the other locations explicitly. The test would fail if any allocation fails. And the existing messages, printed during the test, provide enough information to debug eventual problems. Signed-off-by: Petr Mladek --- lib/livepatch/test_klp_shadow_vars.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/livepatch/test_klp_shadow_vars.c b/lib/livepatch/test_klp_shadow_vars.c index 02f892f941dc..55e6820430dc 100644 --- a/lib/livepatch/test_klp_shadow_vars.c +++ b/lib/livepatch/test_klp_shadow_vars.c @@ -162,15 +162,15 @@ static int test_klp_shadow_vars_init(void) * to expected data. */ ret = shadow_get(obj, id); - if (ret == sv1 && *sv1 == &var1) + if (ret && ret == sv1 && *sv1 == &var1) pr_info(" got expected PTR%d -> PTR%d result\n", ptr_id(sv1), ptr_id(*sv1)); ret = shadow_get(obj + 1, id); - if (ret == sv2 && *sv2 == &var2) + if (ret && ret == sv2 && *sv2 == &var2) pr_info(" got expected PTR%d -> PTR%d result\n", ptr_id(sv2), ptr_id(*sv2)); ret = shadow_get(obj, id + 1); - if (ret == sv3 && *sv3 == &var3) + if (ret && ret == sv3 && *sv3 == &var3) pr_info(" got expected PTR%d -> PTR%d result\n", ptr_id(sv3), ptr_id(*sv3)); @@ -180,7 +180,7 @@ static int test_klp_shadow_vars_init(void) */ sv4 = shadow_get_or_alloc(obj + 2, id, size, gfp_flags, shadow_ctor, &var4); ret = shadow_get_or_alloc(obj + 2, id, size, gfp_flags, shadow_ctor, &var4); - if (ret == sv4 && *sv4 == &var4) + if (ret && ret == sv4 && *sv4 == &var4) pr_info(" got expected PTR%d -> PTR%d result\n", ptr_id(sv4), ptr_id(*sv4)); -- 2.13.7