From nobody Fri May 10 16:51:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1710857217; cv=none; d=zohomail.com; s=zohoarc; b=LOw2D4RZeee+xAgEVoT0Vq2njYUJGy9n7LUPa4XuIuDPKF/DSJkW4noGCcifHZypCR+LJ/+xIGPHd53rwxwyoB9dj8vE7Vc0DDr/FpEQrkJHOC2tI7DsBp63xHK05vMWjLVETFCEVlod/mcq3ZQDOVOmERgZsN0OBGNMm7U9zMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710857217; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=psQLqUsTh68XjulWEvqdNd/ZYkzRdTMVoBlpRemrBz8=; b=lATxuet/uEU2MZbuSjDv47i0SmsFg9BIn62Rgqu1IOA1ZZeyzF3tc6J59mli3mfx+G6wzCSCtGQW9pG9vE2fuoRajAlaiU1pwweIV31TBcAaJmOemp19idlLqgBo8lKUNjKJsgh/N7AqlXqTnGnY8G1hluoNaQj/1VXaKL8uihM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710857217739185.32836667530944; Tue, 19 Mar 2024 07:06:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rma6B-0004Q2-Iy; Tue, 19 Mar 2024 10:05:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rma67-0004PQ-C9 for qemu-devel@nongnu.org; Tue, 19 Mar 2024 10:05:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rma65-0008NV-Tt for qemu-devel@nongnu.org; Tue, 19 Mar 2024 10:05:47 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-695-81on02_uM8qZEN0NMznQdQ-1; Tue, 19 Mar 2024 10:05:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6D49B8007A4; Tue, 19 Mar 2024 14:05:40 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2268A3C20; Tue, 19 Mar 2024 14:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710857145; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=psQLqUsTh68XjulWEvqdNd/ZYkzRdTMVoBlpRemrBz8=; b=WibiUe5urgs2bLKWNSzCDf/cU0dCMA2bEj1QkYlzR5aXsuN6sBDWDOaNBIOgkwe5dVkQ9I 0vbp9zeRP3ZZVLYY8quOonqwbNiBH9E2TqEhJ7uJCjo/kTRyM5WEmm0cDX2K/ZtJzVbxUw uvx+k+sqqALiNc3msHCiaEx/ZidrW34= X-MC-Unique: 81on02_uM8qZEN0NMznQdQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Eric Auger , Yi Liu , Zhenzhong Duan Subject: [PULL 1/3] vfio/iommufd: Fix memory leak Date: Tue, 19 Mar 2024 15:05:14 +0100 Message-ID: <20240319140516.392542-2-clg@redhat.com> In-Reply-To: <20240319140516.392542-1-clg@redhat.com> References: <20240319140516.392542-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.422, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710857220113100001 Coverity reported a memory leak on variable 'contents' in routine iommufd_cdev_getfd(). Use g_autofree variables to simplify the exit path and get rid of g_free() calls. Cc: Eric Auger Cc: Yi Liu Fixes: CID 1540007 Fixes: 5ee3dc7af785 ("vfio/iommufd: Implement the iommufd backend") Suggested-by: Zhenzhong Duan Reviewed-by: Zhenzhong Duan Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index bafddb8f5a9433a3af6a1ce7f5c5a26428da48ea..8827ffe636e2aba1551ba794bf6= 66a7a214590b7 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -118,10 +118,12 @@ static int iommufd_cdev_getfd(const char *sysfs_path,= Error **errp) { ERRP_GUARD(); long int ret =3D -ENOTTY; - char *path, *vfio_dev_path =3D NULL, *vfio_path =3D NULL; + g_autofree char *path =3D NULL; + g_autofree char *vfio_dev_path =3D NULL; + g_autofree char *vfio_path =3D NULL; DIR *dir =3D NULL; struct dirent *dent; - gchar *contents; + g_autofree gchar *contents =3D NULL; gsize length; int major, minor; dev_t vfio_devt; @@ -130,7 +132,7 @@ static int iommufd_cdev_getfd(const char *sysfs_path, E= rror **errp) dir =3D opendir(path); if (!dir) { error_setg_errno(errp, errno, "couldn't open directory %s", path); - goto out_free_path; + goto out; } =20 while ((dent =3D readdir(dir))) { @@ -147,14 +149,13 @@ static int iommufd_cdev_getfd(const char *sysfs_path,= Error **errp) =20 if (!g_file_get_contents(vfio_dev_path, &contents, &length, NULL)) { error_setg(errp, "failed to load \"%s\"", vfio_dev_path); - goto out_free_dev_path; + goto out_close_dir; } =20 if (sscanf(contents, "%d:%d", &major, &minor) !=3D 2) { error_setg(errp, "failed to get major:minor for \"%s\"", vfio_dev_= path); - goto out_free_dev_path; + goto out_close_dir; } - g_free(contents); vfio_devt =3D makedev(major, minor); =20 vfio_path =3D g_strdup_printf("/dev/vfio/devices/%s", dent->d_name); @@ -164,17 +165,13 @@ static int iommufd_cdev_getfd(const char *sysfs_path,= Error **errp) } =20 trace_iommufd_cdev_getfd(vfio_path, ret); - g_free(vfio_path); =20 -out_free_dev_path: - g_free(vfio_dev_path); out_close_dir: closedir(dir); -out_free_path: +out: if (*errp) { error_prepend(errp, VFIO_MSG_PREFIX, path); } - g_free(path); =20 return ret; } --=20 2.44.0 From nobody Fri May 10 16:51:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1710857198; cv=none; d=zohomail.com; s=zohoarc; b=M/jER4+a2F6bWTckFojL6oDOGozuldeEdQu4bHKx23v0ph90LFmnzZwkXNz6kzeQl2uSe58+0s/piEfJiobE+wEyCYjXBV9Bh6qsz8AJC6OWtJKpJy5d7KjZYKE/ft7E5n4h6hu/R9t2hLeSuutdsvc766o7qd+DCsYusw+1C/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710857198; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GeuJyXmk87ew7gCuQ5ySXtgH3p1fHidr/s3r/qeVRMI=; b=UkQrxcAVJF64ikKCTBYtD6xOUYE2YzQoY4XMOWxEKYT8Jy1UPmZbv3tVAuZ+mH1VH2/cUrYCgYgkB/mQ9gE/CEyAKwAfwtRRUP9dKcnqLKhqdR4QnlgEJkZb+tMJbcs2rCeTFLjaISrL72CYYTs9n+b0fIHAc33hfoFKJlGmM9g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710857198089204.98687488237897; Tue, 19 Mar 2024 07:06:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rma6E-0004Va-Un; Tue, 19 Mar 2024 10:05:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rma68-0004Pj-Tq for qemu-devel@nongnu.org; Tue, 19 Mar 2024 10:05:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rma67-0008Ng-FR for qemu-devel@nongnu.org; Tue, 19 Mar 2024 10:05:48 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-163-WGZLw505Okya4wVKHccKhg-1; Tue, 19 Mar 2024 10:05:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id BAA041C04B5B; Tue, 19 Mar 2024 14:05:41 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4DBB3C21; Tue, 19 Mar 2024 14:05:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710857146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GeuJyXmk87ew7gCuQ5ySXtgH3p1fHidr/s3r/qeVRMI=; b=P/oc62qXbsaannbhCjIPESS40TPVjNrkCpKqv6MKPCI9gteUKRZNQSPk1h4mO1Tllnl+AA XXu3PfcJ6XCKa1Lb+96Mj1icNu997uVF1pkBcI1zCO6tKMpl9+MRjZ4OVWvNWLdZhL75oC AkgfKUhbPmXlYHZbl5R6x2BjybpQHf4= X-MC-Unique: WGZLw505Okya4wVKHccKhg-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Glenn Miles , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 2/3] ppc/pnv: I2C controller is not user creatable Date: Tue, 19 Mar 2024 15:05:15 +0100 Message-ID: <20240319140516.392542-3-clg@redhat.com> In-Reply-To: <20240319140516.392542-1-clg@redhat.com> References: <20240319140516.392542-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.422, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710857200088100003 The I2C controller is a subunit of the processor. Make it so and avoid QEMU crashes. $ build/qemu-system-ppc64 -S -machine powernv9 -device pnv-i2c qemu-system-ppc64: ../hw/ppc/pnv_i2c.c:521: pnv_i2c_realize: Assertion `i= 2c->chip' failed. Aborted (core dumped) Fixes: 263b81ee15af ("ppc/pnv: Add an I2C controller model") Cc: Glenn Miles Reported-by: Thomas Huth Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Glenn Miles Signed-off-by: C=C3=A9dric Le Goater --- hw/ppc/pnv_i2c.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/ppc/pnv_i2c.c b/hw/ppc/pnv_i2c.c index 4581cc5e5d4645ab3e358d983a633e33a214c425..eec5047ce83f842108b53a6e2bd= 9869a81f14ac1 100644 --- a/hw/ppc/pnv_i2c.c +++ b/hw/ppc/pnv_i2c.c @@ -557,6 +557,9 @@ static void pnv_i2c_class_init(ObjectClass *klass, void= *data) =20 xscomc->dt_xscom =3D pnv_i2c_dt_xscom; =20 + /* Reason: This device is part of the CPU and cannot be used separatel= y */ + dc->user_creatable =3D false; + dc->desc =3D "PowerNV I2C"; dc->realize =3D pnv_i2c_realize; device_class_set_props(dc, pnv_i2c_properties); --=20 2.44.0 From nobody Fri May 10 16:51:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1710857193; cv=none; d=zohomail.com; s=zohoarc; b=HZDlrwVUMVZx4/7j+9KtMENckqWLbdJSgdezyEvFxyb7RpPlElblHHhlBfWgQBDYrgrasQgRjfII0YPthD2ukXMe57LIaUIm45e9XEr/eagIev68YCMW+4p8WUmZ/gZNMBgilx97wpK0LE0T9jQrqVnRlv2WSvdzJE4fP1hQRwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710857193; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vWgDqLVUGMnlNILpKAU83zv3AF1R8UCIRu3dt5BeHGA=; b=ITnnuMMLpq8uKp7YxLRXPEuCINK+Y6Urn2HjFF6nq0M/Odxzk8r9K5DV1VlYYKHS7e9O5wwKPDbgCv+Na1mGkZUv8up0aKY2++Ix68/FxmmeXDDSQzL4BvufDAOVGe7uRv/F9hTD0q3GLLwroCbHg7w21mGEexCN+M+yqn+TOTw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710857193696961.2389456095858; Tue, 19 Mar 2024 07:06:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rma6C-0004Rt-5X; Tue, 19 Mar 2024 10:05:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rma67-0004PX-Rz for qemu-devel@nongnu.org; Tue, 19 Mar 2024 10:05:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rma66-0008NX-3h for qemu-devel@nongnu.org; Tue, 19 Mar 2024 10:05:47 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-re5I9qv7ObOfGrP4fyGRmQ-1; Tue, 19 Mar 2024 10:05:44 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id C776D1C05AF8 for ; Tue, 19 Mar 2024 14:05:42 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1C673C54; Tue, 19 Mar 2024 14:05:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710857145; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vWgDqLVUGMnlNILpKAU83zv3AF1R8UCIRu3dt5BeHGA=; b=XFOnEuyglgPzWgmZ4j3fyZ5UP027iRr9xHFpWONU31kI0qeiCdmG25HP/dqYhlDft8AAq0 rhjjYDgX7m33heI5aazlsmssfKaCPqYPnSIn/ettjGs3KHIrT1VHNotJ/tiw6dsZwU6QNy qJcSlRMyRnNn422PARaWGhwrVXuoh9w= X-MC-Unique: re5I9qv7ObOfGrP4fyGRmQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Thomas Huth Subject: [PULL 3/3] aspeed/smc: Only wire flash devices at reset Date: Tue, 19 Mar 2024 15:05:16 +0100 Message-ID: <20240319140516.392542-4-clg@redhat.com> In-Reply-To: <20240319140516.392542-1-clg@redhat.com> References: <20240319140516.392542-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.422, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710857196810100003 The Aspeed machines have many Static Memory Controllers (SMC), up to 8, which can only drive flash memory devices. Commit 27a2c66c92ec ("aspeed/smc: Wire CS lines at reset") tried to ease the definitions of these devices by allowing flash devices from the command line to be attached to a SSI bus. For that, the wiring of the CS lines of the Aspeed SMC controller was moved at reset. Two assumptions are made though, first that the device has a SSI_GPIO_CS GPIO line, which is not always the case, and second that it is a flash device. Correct this problem by ensuring that the devices attached to the bus are of the correct flash type. This fixes a QEMU abort when devices without a CS line, such as the max111x, are passed on the command line. While at it, export TYPE_M25P80 used in the Xilinx Versal Virtual machine. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2228 Fixes: 27a2c66c92ec ("aspeed/smc: Wire CS lines at reset") Reported-by: Thomas Huth Reviewed-by: Thomas Huth Tested-by: Thomas Huth [ clg: minor fixes in the commit log ] Signed-off-by: C=C3=A9dric Le Goater --- include/hw/block/flash.h | 2 ++ hw/arm/xlnx-versal-virt.c | 3 ++- hw/block/m25p80.c | 1 - hw/ssi/aspeed_smc.c | 9 +++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h index de93756cbe8f261edf0ff4b4cf2fa811a9c0463d..2b5ccd92f46393b81e373bdd537= a08d66bfd3b8a 100644 --- a/include/hw/block/flash.h +++ b/include/hw/block/flash.h @@ -78,6 +78,8 @@ extern const VMStateDescription vmstate_ecc_state; =20 /* m25p80.c */ =20 +#define TYPE_M25P80 "m25p80-generic" + BlockBackend *m25p80_get_blk(DeviceState *dev); =20 #endif diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c index bfaed1aebfc6f1b60a85520bba44e5276d549cd8..962f98fee2ea9b8643d120100e6= 94cfb00348200 100644 --- a/hw/arm/xlnx-versal-virt.c +++ b/hw/arm/xlnx-versal-virt.c @@ -13,6 +13,7 @@ #include "qemu/error-report.h" #include "qapi/error.h" #include "sysemu/device_tree.h" +#include "hw/block/flash.h" #include "hw/boards.h" #include "hw/sysbus.h" #include "hw/arm/fdt.h" @@ -759,7 +760,7 @@ static void versal_virt_init(MachineState *machine) flash_klass =3D object_class_by_name(s->ospi_model); if (!flash_klass || object_class_is_abstract(flash_klass) || - !object_class_dynamic_cast(flash_klass, "m25p80-generic"))= { + !object_class_dynamic_cast(flash_klass, TYPE_M25P80)) { error_setg(&error_fatal, "'%s' is either abstract or" " not a subtype of m25p80", s->ospi_model); return; diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index 08a00a6d9b89b2883ccab70e665dcf6539caf752..8dec134832a14b03d065080db49= a029d0450acdd 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -515,7 +515,6 @@ struct M25P80Class { FlashPartInfo *pi; }; =20 -#define TYPE_M25P80 "m25p80-generic" OBJECT_DECLARE_TYPE(Flash, M25P80Class, M25P80) =20 static inline Manufacturer get_man(Flash *s) diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c index 3c93936fd1ff98d20b6d6a940768f488d433d879..6e1a84c197130118d022d1b9fb6= 07e74e844f4e2 100644 --- a/hw/ssi/aspeed_smc.c +++ b/hw/ssi/aspeed_smc.c @@ -23,6 +23,7 @@ */ =20 #include "qemu/osdep.h" +#include "hw/block/flash.h" #include "hw/sysbus.h" #include "migration/vmstate.h" #include "qemu/log.h" @@ -695,6 +696,14 @@ static void aspeed_smc_reset(DeviceState *d) for (i =3D 0; i < asc->cs_num_max; i++) { DeviceState *dev =3D ssi_get_cs(s->spi, i); if (dev) { + Object *o =3D OBJECT(dev); + + if (!object_dynamic_cast(o, TYPE_M25P80)) { + warn_report("Aspeed SMC %s.%d : Invalid %s device type", + BUS(s->spi)->name, i, object_get_typename(o)); + continue; + } + qemu_irq cs_line =3D qdev_get_gpio_in_named(dev, SSI_GPIO_CS, = 0); qdev_connect_gpio_out_named(DEVICE(s), "cs", i, cs_line); } --=20 2.44.0