From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 962B8376463 for ; Thu, 25 Jun 2026 08:06:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782374788; cv=none; b=Rs8VQKXh4JbWwvIINg96vrnpBdVVWBC5ku2d4nXpkLjKRrKGMoRKx3FzXYFwjZokCFoyCya2N/coopIDCiHag5UKek1z73gUUxP8zMnwCk1FyIe3QmHnM+18EjHwBBgELg+9G59FoqWlKddqfky6PAHCOwMFf2Hz6dSIrPgXi90= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782374788; c=relaxed/simple; bh=KpLJEsuPBG0Uw22ZXABHSCbqBzaYkFh4xxWwQt4c+Rw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EuKr2i5Sb3DD5jEr9zWubXtWnilN9Tl+7O9mykZYBHsdj2b9N4IDYRq358qkJwJF/iy94VN9rMrg9Rqmw0wnjFPCEEonDVhkkUV1SRbcakwNOf9JC/kgCX97LNjbP5Ca9VHNsXTc4lYa5EDFjHtz1Vdulp4S10YkHZbAor/p7jY= 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=OMXirtzd; arc=none smtp.client-ip=209.85.218.54 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="OMXirtzd" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-c03a466c96aso53021566b.3 for ; Thu, 25 Jun 2026 01:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782374785; x=1782979585; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=0Zxo7YEDpTK4pGpTb+UxYvgaAHrfprADSVL2M5xU7uc=; b=OMXirtzda8djGQDAjfTS3U7THhSQF/dzxVfOrFHKDRYC4eaKkmsj5PFiNmb/PM5v7g JgWNHm+SCq4O6+OYMXZWZtKJCpTCCeg24KmANZGllH3Uf4C0zIMVV+EdTBEuNh96XeQR NmwkdU4VpRRYHp4S6sIrluybKDtOISvGfbbhsNqgdwXgIWnzRAClkHrOtX/06RSnSJ1P cjXTFprs/XtKYT+9by8HEA7VJW1IzxRKJIggfOJVYs3IZ9wd0ZkZct+5Te6cSYuJd4gv 9Rkj5q4HG/+l1JkkHvomRz6btOvM5Kt0ijNHVZ2YLJaveDIieg2a/63i8Pn0oXC2Iz+k zhww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782374785; x=1782979585; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0Zxo7YEDpTK4pGpTb+UxYvgaAHrfprADSVL2M5xU7uc=; b=rC0dya6soCGHi58FL5JXFUVccAlnwBPKzTP30DF7LGqQ15wAsirz6rmpd/nz1WEcBO FBB2dmKHDRttay8QCeBawJIeRwf6F5Iy8x9p1VACFE3loLXuk0H+qi/p/Nt2fb/knb5h 1x/4I9KI6pGQW4bQoekxFzZpBiyjp2bEhvAME7s6qUpz5PM6W3lYtyZ9CB5ygBpct0Wh iiL1tsdNTdxBLJEC8A3BjH0DjkxpRMx+chkmeYWh7VnPp9eNCY1BSA03n3BW5+mgM0qp ebSSTLAIDIQoqMIzFHDpkUp753PNxHFAPn4Edt6qy4tosy4G/88nkYNdzbc0JDrsk+pj L1Kg== X-Forwarded-Encrypted: i=1; AHgh+RqVqspS3SOlt2kfMDw39ZuVIQ/vBvN0IrJRLqAJFVmBomFmOPw33Nu5UVv3U1ulslNhKoFWZjbuLuUBRNE=@vger.kernel.org X-Gm-Message-State: AOJu0YwyxvlKxLTPAA0rcl3kfHg/Aj9hz55sFHGgNu7O3Dq20sy5hVHE C/PPpJeyz/7EoR285qHUy0ASMjy/Vl1jFxwBX4hfEGbOJIi5nTYM7EiZ X-Gm-Gg: AfdE7cllsMQzKzgfyTUATrwRpprT3V94Xo5/GxVNNRCzOjanvK7w7XOap+6Bmgu1mIw 4qzhu+cXqZ6vU6R16XJtMCIBtUibi1rSCnnHn6etcpDn+1hCPNcTofxaJKt/QrNcNMvlGihVs1n PkeYGVerk4VnBoDuVzZxfpc2tmOj16aM96E8fEqv5IiCmI1bF/jiSsvOGev+gyeV1lLF+CaJFOy yRBBR/sQkKGGGltIBLbIem7rO1QWhkMu8OXFjU8KvnWJ9kuor/F9NqFvIOZYaqIZ2NRhiL0gjcp XKEl31WTL3EI1T6uxWa80fkINdH7wvbnUH9DO9bF0gNAigyMABQ5SUslgO+c5PMwF6Ne8nTiONZ 7Mwaegk67ncfe8w7oO8rw45MitEc3ImV/ZIRXmgEhr3zV5PvsH3DeZOAz7/ctZtIDSE6NCf/6/h wgCZmVugEZ X-Received: by 2002:a17:907:f496:b0:c04:93d7:3c12 with SMTP id a640c23a62f3a-c1205ef27ffmr86238466b.25.1782374784710; Thu, 25 Jun 2026 01:06:24 -0700 (PDT) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c11fbe05b6dsm124688066b.37.2026.06.25.01.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2026 01:06:23 -0700 (PDT) Date: Thu, 25 Jun 2026 11:06:20 +0300 From: Dan Carpenter To: Haoxiang Li Cc: marcel@holtmann.org, luiz.dentz@gmail.com, yangyingliang@huawei.com, mst@redhat.com, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] Bluetooth: virtio_bt: fix cleanup paths Message-ID: References: <20260625020159.3446736-1-haoxiang_li2024@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260625020159.3446736-1-haoxiang_li2024@163.com> On Thu, Jun 25, 2026 at 10:01:59AM +0800, Haoxiang Li wrote: > virtbt_probe() registers the HCI device before opening the virtio > Bluetooth device. If virtbt_open_vdev() fails, the error path frees > the HCI device without unregistering it first. The probe error paths > also leak the virtio_bluetooth structure after it has been allocated. > > Rework the probe error handling into an unwind ladder so each failure > path releases the resources acquired earlier. Also close the virtio > device before unregistering the HCI device in virtbt_remove(), matching > the cleanup order used by the probe failure path. > > Fixes: afd2daa26c7a ("Bluetooth: Add support for virtio transport driver") > Fixes: dc65b4b0f90a ("Bluetooth: virtio_bt: fix device removal") > Cc: stable@vger.kernel.org > Signed-off-by: Haoxiang Li > --- > Changes in v2: > - Rework virtbt_probe() error paths into an unwind ladder. > - Free vbt on probe failures. > - Reset the virtio device and unregister the HCI device before freeing it > when virtbt_open_vdev() fails. > - Close the virtio device before unregistering the HCI device in remove(). > > Thanks Dan for the suggestions. The blog is very helpful. > --- > drivers/bluetooth/virtio_bt.c | 23 ++++++++++++++--------- > 1 file changed, 14 insertions(+), 9 deletions(-) > > diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c > index 140ab55c9fc5..4ca9b76f6410 100644 > --- a/drivers/bluetooth/virtio_bt.c > +++ b/drivers/bluetooth/virtio_bt.c > @@ -311,12 +311,12 @@ static int virtbt_probe(struct virtio_device *vdev) > > err = virtio_find_vqs(vdev, VIRTBT_NUM_VQS, vbt->vqs, vqs_info, NULL); > if (err) > - return err; > + goto err_free_vbt; > > hdev = hci_alloc_dev(); > if (!hdev) { > err = -ENOMEM; > - goto failed; > + goto err_del_vqs; > } > > vbt->hdev = hdev; > @@ -383,23 +383,28 @@ static int virtbt_probe(struct virtio_device *vdev) > if (virtio_has_feature(vdev, VIRTIO_BT_F_AOSP_EXT)) > hci_set_aosp_capable(hdev); > > - if (hci_register_dev(hdev) < 0) { > - hci_free_dev(hdev); > + err = hci_register_dev(hdev); > + if (err < 0) { > err = -EBUSY; > - goto failed; > + goto err_free_hdev; > } > > virtio_device_ready(vdev); > err = virtbt_open_vdev(vbt); > if (err) > - goto open_failed; > + goto err_reset_vdev; > > return 0; > > -open_failed: > +err_reset_vdev: > + virtio_reset_device(vdev); I'm not sure that this reset is necessary. I suspect that it isn't, but I don't know for sure. In a situation like this, I'd probably err on the side of only fixing things which I know and leaving the rest as a leak or whatever. Otherwise it looks correct to me. regards, dan carpenter