From patchwork Wed Sep 6 10:10:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1830310 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=rsMPheln; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RgdRs0Q9rz1yh5 for ; Wed, 6 Sep 2023 20:10:49 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=rsMPheln; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RgdRr6T28z3bw9 for ; Wed, 6 Sep 2023 20:10:48 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=rsMPheln; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::530; helo=mail-pg1-x530.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4RgdRf1cHJz2yDd for ; Wed, 6 Sep 2023 20:10:37 +1000 (AEST) Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-573fa7c19c7so199347a12.1 for ; Wed, 06 Sep 2023 03:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693995035; x=1694599835; darn=lists.ozlabs.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8GSDLHX0cSUlED8SVElWjWOUEqu4Z9k09bOV+ZWXM4E=; b=rsMPhelnRRljdZYQWYI3eGF01ACvMRephDBx78yKhChlCEYbEH6XmvjtqPVgccH3ds Ul6for/b1fiik1YITNS1Ur3+gB9tSyW/deV3cH/xKaJ4sBxGjHA1sluaTCXUOEJbT2ZJ Ho1NC684pGdZmbEGgYfj5xKVO5m69t5jbsvXQ0jrgpMDizjHRmIORSuzXHPSNTOs1eiv +/OZ174NkAyFl2set5sGuLfVZK2AoIzVERLT4v6/gqs1+jqsMBqvyIc4HhhMzK6Qd1Vb haGbvHEVpfJzZq7ltDd5OEMz1WOIGAEqDpRBUB5OhDRldoG0YuGC81P2p6ijkGFuYnUJ N+Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693995035; x=1694599835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8GSDLHX0cSUlED8SVElWjWOUEqu4Z9k09bOV+ZWXM4E=; b=Dll4pqkokjVFEFM/PGoHN3KiFITadrBgX4AtSbkkVNk1mvORrH4zRWb1iM//QY0ZcX 0TqXt75Ui4q3YhnY3AuwcdzULmL83Wyup5eB8cAqlWPAxldBz0SU293VPEv52zx09cQ3 F0E3t4IIV9n57m9TA8ZV7SkseKmpat/nRqeeclETa7Oscs8UO8VEMCKDds6FP0rPAXaP ctTXWD9vkgO7roKG4nAHlAVuoaAj0UUpwBt39NXGPmyiWAm+YukYspj4XpcWGF0YbFDs qmLj6Nd53J3KoBmB9peaA0RuLRrHZwjsIRJrANLFAmU/EqYDnEPVH5k1XgPQUb78RgG0 AJ5Q== X-Gm-Message-State: AOJu0YyjI7naxc36P4hrdlgVD394JOs1SQngYBhRPUJNQr55ZlBIIoSv JtJWPPZZlthp6mfhYbPSiczq5A4+Q1w= X-Google-Smtp-Source: AGHT+IGe9Dp7SeYnZpQjEpouoW/Y+IjkZ69WZpUeJ6O4Eb8lRwhlDcZiFeVVgJzG4cTyb8D6LLJNpw== X-Received: by 2002:a17:90a:8689:b0:26d:23c3:9f30 with SMTP id p9-20020a17090a868900b0026d23c39f30mr20577564pjn.14.1693995035445; Wed, 06 Sep 2023 03:10:35 -0700 (PDT) Received: from wheely.local0.net (193-116-105-24.tpgi.com.au. [193.116.105.24]) by smtp.gmail.com with ESMTPSA id m13-20020a17090a7f8d00b002609cadc56esm10639705pjl.11.2023.09.06.03.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Sep 2023 03:10:35 -0700 (PDT) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Wed, 6 Sep 2023 20:10:12 +1000 Message-Id: <20230906101017.130276-3-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230906101017.130276-1-npiggin@gmail.com> References: <20230906101017.130276-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH 2/7] hdata: Use common code for HDIF header check X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Make the HDIF header check use a common function. Signed-off-by: Nicholas Piggin --- hdata/hdif.c | 2 +- hdata/hdif.h | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hdata/hdif.c b/hdata/hdif.c index 2dfa94cf6..13c128c97 100644 --- a/hdata/hdif.c +++ b/hdata/hdif.c @@ -10,7 +10,7 @@ const void *HDIF_get_idata(const struct HDIF_common_hdr *hdif, unsigned int di, const struct HDIF_common_hdr *hdr = hdif; const struct HDIF_idata_ptr *iptr; - if (be16_to_cpu(hdr->d1f0) != 0xd1f0) { + if (!HDIF_check(hdif, NULL)) { prerror("HDIF: Bad header format !\n"); backtrace(); return NULL; diff --git a/hdata/hdif.h b/hdata/hdif.h index 52df0f16d..38df6c271 100644 --- a/hdata/hdif.h +++ b/hdata/hdif.h @@ -63,12 +63,16 @@ struct HDIF_child_ptr { .size = CPU_TO_BE32(_size), \ } -static inline bool HDIF_check(const void *hdif, const char id[]) +static inline bool HDIF_check(const void *hdif, const char *id) { const struct HDIF_common_hdr *hdr = hdif; - return hdr->d1f0 == CPU_TO_BE16(0xd1f0) && - memcmp(hdr->id, id, sizeof(hdr->id)) == 0; + if (hdr->d1f0 != CPU_TO_BE16(0xd1f0)) + return false; + if (id && memcmp(hdr->id, id, sizeof(hdr->id)) != 0) + return false; + + return true; } /* HDIF_get_idata - Get a pointer to internal data block