From nobody Mon Apr 13 10:53:36 2026 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1772898663; cv=none; d=zohomail.com; s=zohoarc; b=L59sTuSkpWkoKBaIWJ0AMdKDXBqjqBO7aZRAT2MZwcmZ/NrOWIjYDEJMZD4bzIFW2Wih8OsCasr6p/sF5l2dUmeoqH5HXJS4szWv7sZihQ7G676BfvCKiOguytgTPujPtRaUYw4aQfm4foncIAM9gSy+AVSLczE7sf4kMNa3RoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772898663; h=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=xU1XG9iYYjPKXUSfPg2ijEBZc0ojBue34vGRwLlKGlw=; b=GQ/wEUFJsOAX0qi5PNx9p8ZdefBlZeadEqBBXUJqdE5zl7ucpqUpdXmTT+e7Lze6jxX19FJYs7rJnD+cbLZGIHJxjpgy4UAuVGbPet/fRbn9eNzEJcE115k98+9IILXvWX/prriz/dVdbFeewwT2aCGSBoNKi3va3s/gr9v7aNk= 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 1772898663051146.58320365676514; Sat, 7 Mar 2026 07:51:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vytvZ-0001ww-Rx; Sat, 07 Mar 2026 10:50:53 -0500 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 1vytvY-0001wh-Oy for qemu-devel@nongnu.org; Sat, 07 Mar 2026 10:50:52 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vytvX-0003Zu-6q for qemu-devel@nongnu.org; Sat, 07 Mar 2026 10:50:52 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-439c5cce2c6so3990180f8f.3 for ; Sat, 07 Mar 2026 07:50:50 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439dad8ec97sm13121750f8f.5.2026.03.07.07.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Mar 2026 07:50:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1772898649; x=1773503449; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xU1XG9iYYjPKXUSfPg2ijEBZc0ojBue34vGRwLlKGlw=; b=xXQWUQvWYM6sdngHmk89obaEZHnya24jHrsocYI/ABGSkhyte+g8cZePJZ2AcIT5ki 6CdhJAHzHn1o4flA+t0ivoBBHKOAWuJKw/D1cY4+AOHKwG2enCVmYdGjdN2/23kb7K5y dYvMIuibkaXt8Ws5LjmpqE7IKa1EYOv91o/PmpCYf+TVhvYiL6BMcBmgbfkcJbRAAXE4 3NYWYCstVEYUeX4cHSIzXOA0Gis12H40HxXmZRApBPjMiYbByymXgz3PeMKXMUndDC/p tRnxQLZYlpnkpTQOIWk8mbXv4HhZbL/D8FIhdyLUfzafDD8/V8Hg7FlOvc54ve8rtRiX geGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772898649; x=1773503449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xU1XG9iYYjPKXUSfPg2ijEBZc0ojBue34vGRwLlKGlw=; b=GhX8iNjTRn1gFcnpGx2xs1yr2FcSG3ItME5jskMA1/9LfyvZ4K2eeaGtxJYE8JIApp 5QCKHLUQkH5dLDW350wIjf++xTEqt//2d9QSmjoVGn7NpfhO0lzEnRs5VBPxckbixtRG f4+aDy/7iu0KeZ3aEm1IRz2faQ/x4yk8Yg8pxeBRUoDeMScvdX6Jev7AgwnRkmIhGnVS WKGDZ7l2qaFVvV8Rmza1H19srrEgljEsimxDkDUwx1r9UAQ98ObQKyXodaZzyAMsAyBI YfmZkdvPQCFWM8L+zQDKI/fxFxzAh7OtI3jV6Rj8LQrvuJBAE+aLzq43snywWuCYuUGB Z6XQ== X-Gm-Message-State: AOJu0YyZz0d3gIkC89C4OCXs2EFtldFTYV1k1PWCbkzCjUTRoLhvH44a dPMw4UDHVOteTjUmiTuq2HHS3YSetOVBiiFBTo3bOBMi+LN+uHJldOtwdHjbaVxvoKP0Zx0IIFy iQRU7 X-Gm-Gg: ATEYQzy/55m0h+niNwviCsznHEdnCMPxvYyKwfcwVTHYzGJtxNSzuKERiXuzHzHvDzl bIKX/ZpyhlWXxxaiWcVT13fqvvesaL0rxxTGz31vblvx8sB7igZxS/IhHp+fHauDUtpLqoUHDPq ZZ7WXfWlfEr6eDaNSzVNhOud0hJGW/Zgj0qvhAeNApqet0AQ6dxk7v+rSAJ3ekrbfMz17UHLwfV VbV+M1a9tD6lM/wl8x7tkMLcXohIQ4bmAnuzDujJ5Ks+197Jqf+I5HXxo2KNnVROd4YUSAVgQSp XADgE0ZulaQgwLK0C3Blp0e7k9Tdm1GZmxfJFQDWgLSPYyMWXC64ENXx1bBBw+YZ+/yf0O6qMfH Tq52UhxJucenvUq6n1H3k68XKVw7WvPlAB94a+TUMR7JulvClYXv4wCdF1RUv2fk+e18sRrMpbk ub4mKzIJKboI5ceHtIHjQNSvV1HOJDFd26HAAA+ckRP49yGLgSd1fNW+RdtVhhMeDbW3bYVqsXK 0nVTFRrT8weTe/T9gJcBZ87rnfeSKQ= X-Received: by 2002:a05:6000:4308:b0:439:ccec:fcd0 with SMTP id ffacd0b85a97d-439da88bce0mr10478669f8f.29.1772898649491; Sat, 07 Mar 2026 07:50:49 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Alessandro Ratti , Markus Armbruster Subject: [PATCH 1/2] hw/qdev: Document qdev_get_dev_path() Date: Sat, 7 Mar 2026 15:50:45 +0000 Message-ID: <20260307155046.3940197-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260307155046.3940197-1-peter.maydell@linaro.org> References: <20260307155046.3940197-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development 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 @linaro.org) X-ZM-MESSAGEID: 1772898664388158500 Content-Type: text/plain; charset="utf-8" We don't document qdev_get_dev_path() at all; in particular we do not mention that it returns a string that the caller must free. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/core/qdev.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/hw/core/qdev.h b/include/hw/core/qdev.h index 4b2730e9d8..29083bc907 100644 --- a/include/hw/core/qdev.h +++ b/include/hw/core/qdev.h @@ -324,6 +324,10 @@ struct BusClass { =20 /* FIXME first arg should be BusState */ void (*print_dev)(Monitor *mon, DeviceState *dev, int indent); + /* + * Return a newly allocated string containing the path of the + * device on this bus. + */ char *(*get_dev_path)(DeviceState *dev); =20 /* @@ -1060,6 +1064,25 @@ bool qdev_set_parent_bus(DeviceState *dev, BusState = *bus, Error **errp); =20 extern bool qdev_hot_removed; =20 +/** + * qdev_get_dev_path(): Return the path of a device on its bus + * @dev: device to get the path of + * + * Returns: A newly allocated string containing the dev path of + * @dev. The caller must free this with g_free(). + * The format of the string depends on the bus; for instance a + * PCI device's path will be in the format:: + * + * Domain:00:Slot.Function:Slot.Function....:Slot.Function + * + * and a SCSI device's path will be:: + * + * channel:ID:LUN + * + * (possibly prefixed by the path of the SCSI controller). + * + * If @dev is NULL or not on a bus, returns NULL. + */ char *qdev_get_dev_path(DeviceState *dev); const char *qdev_get_printable_name(DeviceState *dev); =20 --=20 2.43.0 From nobody Mon Apr 13 10:53:36 2026 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1772898677; cv=none; d=zohomail.com; s=zohoarc; b=J0aFht9e9X6y3fvRtVmiwel3PIh9bSh0poF4KAvxGsbo0YmVjzma9iGDJqmyha1VINYM68uP//pSIab1E0+4kRzCAPUHa59VDmmjuxO7c43UkFg5AorTVJWpceLZgfNkTu9B6YTDcnDBIJI9Ll46Hg8fBUWAy42guHvMmHQGI9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772898677; h=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=vIOiv6RhC5CqYyhTPfJpLbKif/WD1Xb7jVHEWR0mkGA=; b=BbW8BAbMlOZNgI+NAdog0tsoEZa/AXy1whXWHnpNcI7m9S6Dv/W/4k7aqX50LvufyUVO6N78xRFD2jQQC9HogmOASfWbaQ17LCQHqVWY6KAaOfVk3xpC0mb2YkMpDGy2zOLz3J5efgFWgpxFyyYnl4Y4pMqhXmnvJuKOTpVGQ+U= 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 177289867746490.88715710403847; Sat, 7 Mar 2026 07:51:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vytvd-0001yX-9L; Sat, 07 Mar 2026 10:50:57 -0500 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 1vytvZ-0001wy-WF for qemu-devel@nongnu.org; Sat, 07 Mar 2026 10:50:54 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vytvX-0003Zy-T7 for qemu-devel@nongnu.org; Sat, 07 Mar 2026 10:50:53 -0500 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-480706554beso111861275e9.1 for ; Sat, 07 Mar 2026 07:50:51 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439dad8ec97sm13121750f8f.5.2026.03.07.07.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Mar 2026 07:50:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1772898650; x=1773503450; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vIOiv6RhC5CqYyhTPfJpLbKif/WD1Xb7jVHEWR0mkGA=; b=bbVA+7HtrO9cBgpHJu/y3tUeIdL2TL794OJ77GB7NcGDV+IVMFw8udn6W33bnzq258 y0IhJsPlrAYMqkOS69V/AYqrBxgamB8Hcxp1LflI6c1BGX8+d7k+LV/c4Wqe4pbyweIM DoQkDPZPeQ7y2tt5xv2iakTgyrQ0QyfCOJDmdYG9TgJpaym5S5H0spZ6lcbT+U5Voqz7 m9woruet4ww8wA+ftZusMxN5Xz/r2PTGCvKOjcV2udfOlsNlFMT/btVC0FfkfLTFGKkB NOb4oxVWMYMifnfAhRAmaMH4N4YJwzHixmmWD1mg58r5CVrVGTgxsCZt4+JxLo1GiEJb PWjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772898650; x=1773503450; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vIOiv6RhC5CqYyhTPfJpLbKif/WD1Xb7jVHEWR0mkGA=; b=EI+thMeHzOJTdULorgDhfvIIliUxzgV/17EjhsWEwazcfuMkKn8Bap/jCmDea2TZ+q WFYASuIUYOo/xPk69uFKSolWbScdFnL+EIDcTLv/r57BqMOUrFrT42poj3GzhOciNI8t 6fVTCiFabHXGA3zOVeuIoI7DF8JaebpwtTJwRgNRkMv/n9yQm9z1uAAtoaSYT1K2mJcX wLajE/SiWKsagYf5wEB11CIfij9ziNo6W2IYaF3Bn5ogXohDOW4OzrLCepBHJrAhVdyG sq4oEJ1G5XtFvYV+M+wsvMUNnVXcpwo+p7+RhRnw9HwhG0g6SU3zmvqqYUNeUdnS1q9L jU2Q== X-Gm-Message-State: AOJu0YyGTFO3V0SlRHEmSfjRfvts7R6LH7wV7WadmKIu555piD1KdlBB YjaZHBvY1LN00JJryZjoku9UupBw2t00nOv7IVdcC3NNcXn5JOYKkLrKlaHFUFy4Sa7WAPeJB7/ Qvt4W X-Gm-Gg: ATEYQzyrHtrX1OD18wYVnqLQPE6VNBz/jBhOLBfp6QHYPXifZAbyguhOY+zLH9NrhZg ozEHCa+2mcacMYsSpGXaWb3Tsv3C9Ik8IZLKk1PQJTs5J4PTwvvMiw7yNOcbzUVLjkclVrkdKk0 Et8qnhd4+1hZCdyNRMavgpQXTj50cTNwFARClEay/W6h9MaPCkK7s5cJIgKWwfDgUMaKCPvT7HZ qCfeXyR6IE8HfkTQV+Rev49wiMHq5swdzFu6oqB6Ei7CjMp4X4tGi8z/l304MRwk36c8vWSYEY6 5vrEi7pKHaIgjArBjsWgTL6oQZythu4lfH519XSwXYAINS37kQpxdVVZIWczuF6C3V3bl59qmql lyopKINxEX5yqPOEDBZNLN7itt5k/RVyX5zjf6hqN0Q2+o8mm8Rbv1B3+bhFzYOmmY0zpo16PWs 1zYr8zcV4roFgFXbKYTaK8LWHJqoI0lmbmTaqjZ2wMP6JGfEdzAKPO6Q4izEB9wlut+TQQThKon jQWL1VOCRbtWxGl5L29DnzaVRoi1rU= X-Received: by 2002:a05:600c:8b86:b0:485:3473:d4a1 with SMTP id 5b1f17b1804b1-4853473d6dcmr4104205e9.34.1772898650375; Sat, 07 Mar 2026 07:50:50 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Alessandro Ratti , Markus Armbruster Subject: [PATCH 2/2] hw: Make qdev_get_printable_name() consistently return freeable string Date: Sat, 7 Mar 2026 15:50:46 +0000 Message-ID: <20260307155046.3940197-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260307155046.3940197-1-peter.maydell@linaro.org> References: <20260307155046.3940197-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::32a; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development 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 @linaro.org) X-ZM-MESSAGEID: 1772898678511158500 Content-Type: text/plain; charset="utf-8" The current implementation of qdev_get_printable_name() sometimes returns a string that must not be freed (vdev->id or the fixed fallback string "" and sometimes returns a string that must be freed (the return value of qdev_get_dev_path()). This forces callers to leak the string in the "must be freed" case. Make the function consistent that it always returns a string that the caller must free, and make the three callsites free it. This fixes leaks like this that show up when running "make check" with the address sanitizer enabled: Direct leak of 13 byte(s) in 1 object(s) allocated from: #0 0x5561de21f293 in malloc (/home/pm215/qemu/build/san/qemu-system-i38= 6+0x1a2d293) (BuildId: 6d6fad7130fd5c8dbbc03401df554f68b8034936) #1 0x767ad7a82ac9 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0= x62ac9) (BuildId: 116e142b9b52c8a4dfd403e759e71ab8f95d8bb3) #2 0x5561deaf34f2 in pcibus_get_dev_path /home/pm215/qemu/build/san/../= ../hw/pci/pci.c:2792:12 #3 0x5561df9d8830 in qdev_get_printable_name /home/pm215/qemu/build/san= /../../hw/core/qdev.c:431:24 #4 0x5561deebdca2 in virtio_init_region_cache /home/pm215/qemu/build/sa= n/../../hw/virtio/virtio.c:298:17 #5 0x5561df05f842 in memory_region_write_accessor /home/pm215/qemu/buil= d/san/../../system/memory.c:491:5 #6 0x5561df05ed1b in access_with_adjusted_size /home/pm215/qemu/build/s= an/../../system/memory.c:567:18 #7 0x5561df05e3fa in memory_region_dispatch_write /home/pm215/qemu/buil= d/san/../../system/memory.c #8 0x5561df0aa805 in address_space_stm_internal /home/pm215/qemu/build/= san/../../system/memory_ldst.c.inc:85:13 #9 0x5561df0bcad3 in qtest_process_command /home/pm215/qemu/build/san/.= ./../system/qtest.c:480:13 Cc: qemu-stable@nongnu.org Fixes: e209d4d7a31b9 ("virtio: improve virtqueue mapping error messages") Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/core/qdev.c | 4 ++-- hw/virtio/virtio.c | 12 +++++++++--- include/hw/core/qdev.h | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index fc3425a8fe..e48616b2c6 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -420,7 +420,7 @@ const char *qdev_get_printable_name(DeviceState *vdev) * names. */ if (vdev->id) { - return vdev->id; + return g_strdup(vdev->id); } /* * Fall back to the canonical QOM device path (eg. ID for PCI @@ -437,7 +437,7 @@ const char *qdev_get_printable_name(DeviceState *vdev) * Final fallback: if all else fails, return a placeholder string. * This ensures the error message always contains a valid string. */ - return ""; + return g_strdup(""); } =20 void qdev_add_unplug_blocker(DeviceState *dev, Error *reason) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 22d798e6cd..db6e08c13b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -281,10 +281,12 @@ void virtio_init_region_cache(VirtIODevice *vdev, int= n) len =3D address_space_cache_init(&new->desc, vdev->dma_as, addr, size, packed); if (len < size) { + g_autofree const char *devname =3D qdev_get_printable_name(DEVICE(= vdev)); + virtio_error(vdev, "Failed to map descriptor ring for device %s: " "invalid guest physical address or corrupted queue setup", - qdev_get_printable_name(DEVICE(vdev))); + devname); goto err_desc; } =20 @@ -292,10 +294,12 @@ void virtio_init_region_cache(VirtIODevice *vdev, int= n) len =3D address_space_cache_init(&new->used, vdev->dma_as, vq->vring.used, size, true); if (len < size) { + g_autofree const char *devname =3D qdev_get_printable_name(DEVICE(= vdev)); + virtio_error(vdev, "Failed to map used ring for device %s: " "possible guest misconfiguration or insufficient memory", - qdev_get_printable_name(DEVICE(vdev))); + devname); goto err_used; } =20 @@ -303,10 +307,12 @@ void virtio_init_region_cache(VirtIODevice *vdev, int= n) len =3D address_space_cache_init(&new->avail, vdev->dma_as, vq->vring.avail, size, false); if (len < size) { + g_autofree const char *devname =3D qdev_get_printable_name(DEVICE(= vdev)); + virtio_error(vdev, "Failed to map avalaible ring for device %s: " "possible queue misconfiguration or overlapping memory reg= ion", - qdev_get_printable_name(DEVICE(vdev))); + devname); goto err_avail; } =20 diff --git a/include/hw/core/qdev.h b/include/hw/core/qdev.h index 29083bc907..f99a8979cc 100644 --- a/include/hw/core/qdev.h +++ b/include/hw/core/qdev.h @@ -1084,6 +1084,22 @@ extern bool qdev_hot_removed; * If @dev is NULL or not on a bus, returns NULL. */ char *qdev_get_dev_path(DeviceState *dev); + +/** + * qdev_get_printable_name: Return human readable name for device + * @dev: Device to get name of + * + * Returns: A newly allocated string containing some human + * readable name for the device, suitable for printing in + * user-facing error messages. The function will never return NULL, + * so the name can be used without further checking or fallbacks. + * + * If the device has an explicitly set ID (e.g. by the user on the + * command line via "-device thisdev,id=3Dmyid") this is preferred. + * Otherwise we try the canonical QOM device path (which will be + * the PCI ID for PCI devices, for example). If all else fails + * we will return the placeholder ". + */ const char *qdev_get_printable_name(DeviceState *dev); =20 void qbus_set_hotplug_handler(BusState *bus, Object *handler); --=20 2.43.0