From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 315FB25F7A5 for ; Sat, 27 Jun 2026 10:48:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782557284; cv=none; b=X1ldU/K8m+S2XTWd/4JDHqBqu4aKh2+3T2K3mQxu+6R7hc4TGXK21ErFIN8KPRwNhLz4gcJ4sM3cKL6xg1siWjEMh0wPnZ5abkGVMJDNtblhOeSwNm8sdRM1HgHhx9YKY6Y7RRdmefYIJ+MYLDw/xoVs/iySVyVS/c4N+6SkuHg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782557284; c=relaxed/simple; bh=5f9DRxCgxvpKHvnJSiV97tR0B71w7wB17eQP9/xYHCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eqhdOhVV09fBRZvM4fPoAf/srD0G2Iv5SdWxP+jrau4USN8RKPzuo2qW08NTJDhX1T+wbwTbftGp6IxzNp0lPu0u85VZ3No3NkMNo/GapERV7q4DsfwiAgrn6wPwSnvXYzCjPToIl5rySe4dxbwLnPwgQUr5faeBOWakoUToWIc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=NbUsJCOS; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="NbUsJCOS" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782557280; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q0bXOJE6tHd+pYP54YvtCZ62SW/PO7nF/2RtSUXtdbs=; b=NbUsJCOSsl1Jk+ovYIzpsmnNxWblZ8TSUR/uaew+DboEHMZeBqZN0s49UTPUWW6h+EUFmA bXo1OceTlVnhFvjWVQH/HXSRdmLYeiqN56CfEaIbsQCpVQx5piunhteRkItMFLYsZ0sP5T O45xuOtUlSC32NdtTSe59tzZ/wlax7Y= From: Thorsten Blum To: Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" Cc: Thorsten Blum , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] powerpc/pseries/ras: Use struct_size() to simplify fwnmi_get_errinfo() Date: Sat, 27 Jun 2026 12:47:31 +0200 Message-ID: <20260627104730.276858-4-thorsten.blum@linux.dev> In-Reply-To: <20260627104730.276858-3-thorsten.blum@linux.dev> References: <20260627104730.276858-3-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2201; i=thorsten.blum@linux.dev; h=from:subject; bh=5f9DRxCgxvpKHvnJSiV97tR0B71w7wB17eQP9/xYHCA=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFn2q3w19hQyGdydaWfbInupj5NvcW+8ls430TT/V9YaT yJOdit0lLIwiHExyIopsjyY9WOGb2lN5SaTiJ0wc1iZQIYwcHEKwERecDP8T5Gruv1GdJJS2l3/ uOdRETkq37dYdm1N6T8kMEsi5L15FsP/pGsFG878ebV8b7IV/9GJyjaOUx+f90ho+LO1/s3qUDV XLgA= X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Now that struct rtas_error_log uses a flexible array member for the extended log buffer, use struct_size() to calculate the total RTAS error log size and avoid using the hard-coded header size of 8 bytes. Signed-off-by: Thorsten Blum --- Changes in v2: - memcpy_and_pad() cannot be used in real mode; use memset() + memcpy() - v1: https://lore.kernel.org/r/20260626184750.166642-4-thorsten.blum@linux.dev/ --- arch/powerpc/platforms/pseries/ras.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c index adafd593d9d3..7b8713bdd978 100644 --- a/arch/powerpc/platforms/pseries/ras.c +++ b/arch/powerpc/platforms/pseries/ras.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -440,6 +441,8 @@ static __be64 *fwnmi_get_savep(struct pt_regs *regs) static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs) { struct rtas_error_log *h; + u32 extended_log_length; + size_t len; __be64 *savep; savep = fwnmi_get_savep(regs); @@ -449,17 +452,12 @@ static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs) regs->gpr[3] = be64_to_cpu(savep[0]); /* restore original r3 */ h = (struct rtas_error_log *)&savep[1]; + extended_log_length = rtas_error_extended(h) ? rtas_error_extended_log_length(h) : 0; + len = struct_size(h, buffer, extended_log_length); + len = min(len, RTAS_ERROR_LOG_MAX); /* Use the per cpu buffer from paca to store rtas error log */ memset(local_paca->mce_data_buf, 0, RTAS_ERROR_LOG_MAX); - if (!rtas_error_extended(h)) { - memcpy(local_paca->mce_data_buf, h, sizeof(__u64)); - } else { - int len, error_log_length; - - error_log_length = 8 + rtas_error_extended_log_length(h); - len = min_t(int, error_log_length, RTAS_ERROR_LOG_MAX); - memcpy(local_paca->mce_data_buf, h, len); - } + memcpy(local_paca->mce_data_buf, h, len); return (struct rtas_error_log *)local_paca->mce_data_buf; }