From patchwork Thu Jan 16 13:18:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thorsten Blum X-Patchwork-Id: 13941673 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 A2CAF1DE4FF for ; Thu, 16 Jan 2025 13:20:07 +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=1737033610; cv=none; b=mD+GpDxKccA4o6DpZ/HXnVR9ZvrZf5LrLfisp1uWyXTCv32vrhlY/CafH9nhweCN08Ys05ELHLV53KN8MhATK8fTWNYrUiSVin44/HOUPQXBeG41SNT/22PU5Nq5dHjRFqtETLLP4Vy6IoqTzzzHOgcpJ8p1yQTRXFlUFFsS01o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737033610; c=relaxed/simple; bh=JLbzrkPHHl4z3OfrMXHdkLR2wYyEFz7nDvkukN04Yns=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=u16ackSKcpBcsff4JyuwHfKbnESwpPyVbILcz7urmf94u4q1LuceNqUCWrFrvzi19OMZcPVoa+lgStkOD0+9qYx5PzG0D8ew+H9wsv788G3ESgis6C9774t8q7z1mRJ3l7WQwuUsL6Fz6RXxJLvDbzF/5NhRAhCJC8yMedhRD24= 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=MR2RdUZI; 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="MR2RdUZI" 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=1737033589; 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; bh=KCtIlCqqSrO4jJm7cqUf8hZlN4VmB46QY7zufEspPzQ=; b=MR2RdUZI0IBjFtTp2atANEKRTb5K+2PvOTA2NZaeYgdNKkhQQYZWxMM6nWeYUFLAhM6Jrt 4fRWK3SwWQE6PwKtZlf9t18usGoWAIuGL4gZ1iPq5yR89uRLxJQXe2LFd+tyQZc6s1brwf SBEM2bbUoxoYNb2qNzI4SQVUodGdFVM= From: Thorsten Blum To: Tony Krowiak , Halil Pasic , Jason Herne , Harald Freudenberger , Holger Dengler , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle Cc: linux-hardening@vger.kernel.org, Thorsten Blum , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] s390/vfio-ap: Replace one-element array with flexible array member Date: Thu, 16 Jan 2025 14:18:59 +0100 Message-ID: <20250116131859.105756-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Replace the deprecated one-element array with a modern flexible array member in the struct ap_matrix_dev. Use struct_size() to calculate the number of bytes to allocate for matrix_dev with a single mdev_type. Link: https://github.com/KSPP/linux/issues/79 Signed-off-by: Thorsten Blum --- drivers/s390/crypto/vfio_ap_drv.c | 2 +- drivers/s390/crypto/vfio_ap_private.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c index 67a807e2e75b..ea9ffa37f263 100644 --- a/drivers/s390/crypto/vfio_ap_drv.c +++ b/drivers/s390/crypto/vfio_ap_drv.c @@ -96,7 +96,7 @@ static int vfio_ap_matrix_dev_create(void) if (ret) goto bus_register_err; - matrix_dev = kzalloc(sizeof(*matrix_dev), GFP_KERNEL); + matrix_dev = kzalloc(struct_size(matrix_dev, mdev_types, 1), GFP_KERNEL); if (!matrix_dev) { ret = -ENOMEM; goto matrix_alloc_err; diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h index 437a161c8659..9aed8994f567 100644 --- a/drivers/s390/crypto/vfio_ap_private.h +++ b/drivers/s390/crypto/vfio_ap_private.h @@ -53,7 +53,7 @@ struct ap_matrix_dev { struct mutex guests_lock; /* serializes access to each KVM guest */ struct mdev_parent parent; struct mdev_type mdev_type; - struct mdev_type *mdev_types[1]; + struct mdev_type *mdev_types[]; }; extern struct ap_matrix_dev *matrix_dev;