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 9E0813B7B97 for ; Fri, 26 Jun 2026 18:48:57 +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=1782499739; cv=none; b=SW3waU9hPKi1MvfJAXUDb/qiei1YFqiXeICRJkyyaUpS1vvahe3xit2YKe8ayPqHocIg+zlm+d7K+z/lrsIcxP5DRG/e9oQPxUw/QTwKNBTB8gfw+dfXs1tpT+MzCuT868VjPW1XUJm/wUZH0ooh1nSy8l/sB9A5CKtrVoO56Bw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782499739; c=relaxed/simple; bh=YXjaVhhauUwhC8W0e+m1P/XaX9aBADxcZZNQnVrjEwE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fLy8QmJ2ZYUZUqrEFedFzKEkVpe95V6xoXyv/fBnfwWxb/eTzsAHXKYAzcVaS+IcKJKiPU8C/kVXMW/3lz3pyHO3W0dehgfUUEHsMSftykI6h27+sfgCBh3ni66uV6ygZtGM+7rafC7d3s0MuQnkC4SpeRwi4DWUZqljlZ7YSm0= 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=pKQrfZPi; 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="pKQrfZPi" 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=1782499735; 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=BXR2tZurJ1eKqJHB84SXKvdWd2G7Lw74Pt5/iYEF5lI=; b=pKQrfZPi/g5/Vb3Iry3kNNhrHXh2hJh9KJN149Dkx4ORUxOBvnUQM9rqYb5MrzbMUmcC2n faeVqPRvreW5bmReiHTGCKvJ1JqLHtwM9rLTpqh04+VV3rt/pU3x7L+KKKaF6QA26B+ImP 5zJZgklWIGB+qufbboycDjHYk/wvyeU= 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 2/2] powerpc/pseries/ras: Use struct_size() to simplify fwnmi_get_errinfo() Date: Fri, 26 Jun 2026 20:47:50 +0200 Message-ID: <20260626184750.166642-4-thorsten.blum@linux.dev> In-Reply-To: <20260626184750.166642-3-thorsten.blum@linux.dev> References: <20260626184750.166642-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=2128; i=thorsten.blum@linux.dev; h=from:subject; bh=YXjaVhhauUwhC8W0e+m1P/XaX9aBADxcZZNQnVrjEwE=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFl2JxOufz4qE5PO9UlBOTKjkjP4w+kqHpPI4JWsZ9kuJ P/zWraro5SFQYyLQVZMkeXBrB8zfEtrKjeZROyEmcPKBDKEgYtTACaS1s7wT63z9qkr/R4dQa0P 1Zj5FtYdFbnzlnsPn2tDfEbcZCumXwz/9A1+7cox3bKMLTbL0Cl2g1LFZhfOVImNKyqPcfeKb1n CAgA= 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. Use memcpy_and_pad() instead of memset() and memcpy() while at it. Signed-off-by: Thorsten Blum --- arch/powerpc/platforms/pseries/ras.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c index adafd593d9d3..d54030fd2324 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,11 @@ 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_and_pad(local_paca->mce_data_buf, RTAS_ERROR_LOG_MAX, h, len, 0); return (struct rtas_error_log *)local_paca->mce_data_buf; }