From nobody Tue Apr 7 17:55:55 2026 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 848AF274FDF for ; Thu, 12 Mar 2026 05:08:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773292113; cv=none; b=Lqzlh9PVEvVBbnfHowz2SP+nZwf8+3D0lfefftv0B0c4TdZJkXO7BDvsyCtt0GblqR2yVzUdeJTIxeXU2w+603u6c6lq6FEatojTZ5XNhmltQjJBaS7HsAcG3T2CO6EsRtNCIF0FRka/g33elkcrXLYwRzp5HYhvZzi3nUcAD2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773292113; c=relaxed/simple; bh=VoUnsqUa2CjJvSkODbwmVCtNMW5aOlRcr358eQoOc1s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dnJAlFVQ87SXUde76sUhEfyLx5lMJ7yAogl4ZPloucG5hXAnADIiG+tTBxxfXfonWk10StfSfUhiG3CHFgcvkdJsIivmmXW30dQYSpaMNxo8XGZ0lIm1rFPnX1GGXFkOzBO5vfbrH2tp804V93Q51H1lvdH25T++/3Di5Z/zOmw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jxfy8ZyW; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jxfy8ZyW" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-35a1a36f0c0so59676a91.2 for ; Wed, 11 Mar 2026 22:08:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773292112; x=1773896912; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qLyWI/vZ6KJ+d4HD/0yXDVb44fVq/X3hpM9ycM+cxjc=; b=jxfy8ZyWtJLsmZnOeDmwPDWWkffARsHuhAFr7CmVzpvV8hdPyAtgfaw2tdEXW/riNL Kp3uo9HwT3yby293nmBCHXhubc1w9Wn+fuGHzu2QKy1wgqRhyo+GLNrk9Jt5tBsE6axw fa2EOfHqoKCl6XdKE/SVYm0/sTUzWV7p7ZXdhOeFtVkY7OEPCMda69Cu/VAj5RbX7i2C xmpY9GBBxc+jW10SoBlsAswP3vlN9xreUaYXozHolx62Ua2yTCoaNgXM78vw5mzJGNfE i5T+xNIQ3+31BQsw+X00KEQwoGXHySD7cVLHDNsmd/bsSqqZiSp3Wdwn6f6/vPcai7Uj eLGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773292112; x=1773896912; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qLyWI/vZ6KJ+d4HD/0yXDVb44fVq/X3hpM9ycM+cxjc=; b=l9Si2lvlxon54R83yvHmKi+MirLVGjlbD/v1KSF9K7vS5rRTu5vuOLf1W/ImjrOd85 O9GvZF9oDGgKOvzyTht05KCrmDSxx+xnCEhk2l/tNb9P7Ye4J50M+fuXeifz5CumD72+ 8EOME4YAUioGHxBo2rWHSCD6KmFI3iiOpaoRYoZ2TIARcrDX/4u/ZmxjWX6tTg8t3uNQ SMmwLWiBs1JPRweEfC81NVl/P0V4anWIfuM1ktVO1+EjpX4kr3uVciCoJAVz9e9iqWHa Tfm9bWZTFuYewmdoVFF0x665WZy58vvIe9DCA7eUrkH4ffk+yOOuhhy1YHatzBR+zyxK yPdA== X-Forwarded-Encrypted: i=1; AJvYcCVtVnBSSlmI7B5HGcDQTUUy5nmMFvAM/lKiHCF0bvsE4m5BtzAEB/gtRURZS0iibTY4SWwioJ1+tUBmbOQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxzDwmgMxw3UM/2tHWWZ4dtJZ6yrSqOxPaia5pfisxNhX1/A1eS dJrvKJvYOjCfr7MO0xYw8449jhENRNhdH330EAckYHNJDV0ZzpHOJLGT X-Gm-Gg: ATEYQzxieQ8Y0YZiEVgrs+LWqUUc/lEoo6DT9d95LvEQRNnPuQhsxMBYqu+pC7NX4a6 Ut9+qFfkDSmQUQTcqV+SXqPauN4/vrRA/ABuU5KAsJrWESLWzsNs9z0p/UIO/QEb/4GFnnrzo+Q SoW31hrtSyD5xnQ1/el9mQz+im+vV0lo++JF6HtJiaC+D58LAGUoszGGDgC75FHdEOrPIzecziH TnPQWRxQYND2Hdwyc6O99oo96o+XkknCneH1xcZ6nT6DaF37ZGA1SMMY7JIVI3MpEgdzNXyfTSQ vX4+4ZotIcVMGiYcrDYk4XnTasUVzPmSUANOZDoRp9FOTaBT6o6eOYmQ6w3KfUYm3B2b9/3jtJE qbArFaUrufuhvKpvRGyLJv+0sujtKYZXKKOXkjrrjTuloYuHk/FAz38ZsXE62GAfwBTVa2ypVLU Be2U5/KyX76Fu4QWMkVzjYqQjnLewkh3evsZId+G37XV/2qXoyJl/Luw== X-Received: by 2002:a17:903:2b0c:b0:2ae:3dcc:eb19 with SMTP id d9443c01a7336-2aeae7be9b2mr55414965ad.19.1773292111873; Wed, 11 Mar 2026 22:08:31 -0700 (PDT) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2aeae2228f5sm42044625ad.16.2026.03.11.22.08.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 22:08:31 -0700 (PDT) From: Rosen Penev To: linux-edac@vger.kernel.org Cc: Borislav Petkov , Tony Luck , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH] EDAC/mc: Use kzalloc_flex() Date: Wed, 11 Mar 2026 22:08:13 -0700 Message-ID: <20260312050813.9915-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Change kzalloc + kcalloc to just kzalloc with a flexible array member. Add __counted_by for extra runtime analysis when requested. Move counting assignment immediately after allocation as required by __counted_by. Signed-off-by: Rosen Penev Reviewed-by: Yazen Ghannam --- drivers/edac/edac_mc.c | 9 ++------- include/linux/edac.h | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 29e9828422bb..1ffab0269aec 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -203,7 +203,6 @@ static void mci_release(struct device *dev) kfree(mci->csrows); } kfree(mci->pvt_info); - kfree(mci->layers); kfree(mci); } =20 @@ -361,25 +360,21 @@ struct mem_ctl_info *edac_mc_alloc(unsigned int mc_nu= m, per_rank =3D true; } =20 - mci =3D kzalloc_obj(struct mem_ctl_info); + mci =3D kzalloc_flex(*mci, layers, n_layers); if (!mci) return NULL; =20 - mci->layers =3D kzalloc_objs(struct edac_mc_layer, n_layers); - if (!mci->layers) - goto error; - mci->pvt_info =3D kzalloc(sz_pvt, GFP_KERNEL); if (!mci->pvt_info) goto error; =20 + mci->n_layers =3D n_layers; mci->dev.release =3D mci_release; device_initialize(&mci->dev); =20 /* setup index and various internal pointers */ mci->mc_idx =3D mc_num; mci->tot_dimms =3D tot_dimms; - mci->n_layers =3D n_layers; memcpy(mci->layers, layers, sizeof(*layer) * n_layers); mci->nr_csrows =3D tot_csrows; mci->num_cschannel =3D tot_channels; diff --git a/include/linux/edac.h b/include/linux/edac.h index fa32f2aca22f..deba46b3ee25 100644 --- a/include/linux/edac.h +++ b/include/linux/edac.h @@ -541,17 +541,6 @@ struct mem_ctl_info { struct csrow_info **csrows; unsigned int nr_csrows, num_cschannel; =20 - /* - * Memory Controller hierarchy - * - * There are basically two types of memory controller: the ones that - * sees memory sticks ("dimms"), and the ones that sees memory ranks. - * All old memory controllers enumerate memories per rank, but most - * of the recent drivers enumerate memories per DIMM, instead. - * When the memory controller is per rank, csbased is true. - */ - unsigned int n_layers; - struct edac_mc_layer *layers; bool csbased; =20 /* @@ -609,6 +598,18 @@ struct mem_ctl_info { u8 fake_inject_layer[EDAC_MAX_LAYERS]; bool fake_inject_ue; u16 fake_inject_count; + + /* + * Memory Controller hierarchy + * + * There are basically two types of memory controller: the ones that + * sees memory sticks ("dimms"), and the ones that sees memory ranks. + * All old memory controllers enumerate memories per rank, but most + * of the recent drivers enumerate memories per DIMM, instead. + * When the memory controller is per rank, csbased is true. + */ + unsigned int n_layers; + struct edac_mc_layer layers[] __counted_by(n_layers); }; =20 #define mci_for_each_dimm(mci, dimm) \ --=20 2.53.0