From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385952; b=rAlhRMyh/VswyJ4hx2FxmEmxVqV3Zi1j8XENJz3nZvst3SybeXdud1c2a0DX6naeZEmU BrXuxs3fxtS8j/Vi/Faa5njqXam5YhnQUVA1ErTnZw2S77YPfeZEzsu1EJBGG7xxhaTMY IP1IhRdlrBZuqpr/MLAGDzXaYjsQNu40TsHZFoBRa1xk/TJeAnuKTK0RaWVW663MrAhmJ 93buuGCT1+KVvLa42zp5ofnQwIKmatU/mVnBfc8Q6n/MNdHH7q0yuDuUcFImWlOV4mSeD HJF5ULRTIrBblUgjjsXHZpPfVr2ds6gSRXXWrDCxoagQUuRvDxHET9PepvFWAktQWbA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385952; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=NepGOo7NMnSG1HE6vf+t60ohIZ9Ido3P1OT1EZTzPW0=; b=nDBiYAIjVtz/EIwAdLc/i6S43sMVd/ohamv9QJMHVLjN4VdYHPl8VL7/Ix8JYLczXVyE qSBDWAo9cggiRApOXjAtlT+VDmDdNRTpJgTjjkFZp9yLcljOcLKLoF5At7gc8RGYwXQyB ut4Q8yA68NR5AJna7+5jkWLJjFdhXWNLYqKD9k0b0yCta/bfUue3Lzr315uB2BlJh5u44 O5m1OYDA8cC8XcWDj+jlBtmxLLW6Raso/VmkVXKSqz/jlnlIekwOdyDYCxeFzc1SpcTIS ZAhTS6JwfF+PBWZEYPuVG9DiawjowN/XH/fS8eG+hGzH83qtZE/A6gMIjHL/epRiRxQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=oUdCzNEG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7865606A32C; Fri, 4 Dec 2026 12:05:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=oUdCzNEG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E4681F000C2; Fri, 4 Dec 2026 12:05:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385952; bh=NepGOo7NMnSG1HE6vf+t60ohIZ9Ido3P1OT1EZTzPW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oUdCzNEGD+pEp5ol9EyI/+2bT2TxDDbC7zTt1BIaVQ01UC863RkvmicM2suSl25Di XLw4SJDzgj3rryxzkxFQSelCH+7D6N18ruI75An0HS8CM16kHvRYxz/hfbsxo69Opz Vr4Bn9HiOOl6jT2sqIuHGHwwa5wEBqQehUtx/B3U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Wentao Liang , Ian Abbott , Sasha Levin Subject: [PATCH 6.6 0760/1167] comedi: comedi_bond: Fix leak of opened device references Date: Fri, 4 Dec 2026 19:03:07 +0900 Message-ID: <20261204100721.874410335@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ian Abbott commit fa0858523f07f8dd71d89b221f4422c3b8096d90 upstream. bonding_attach() calls do_dev_config() to open other comedi devices specified by the user and tries to make use of them as part of the 'bonding' device. If it successfully opens the other device but cannot use it (either because it does not any subdevices of a type the 'bonding' device can use, or because of some error that occurs while dealing with its subdevices) then it is left in the open state and the fact that it is open does not get recorded by the 'bonding' device, so the reference to the opened device gets lost. Fix it by closing the opened device if it could not be bound to the 'bonding' device. To match previous behavior, if the opened device is unsuitable then ignore it (after closing it). The opened devices recorded by the 'bonding' device will eventually get closed by bonding_detach() even if bonding_attach() returns an error. Fixes: 3cf840f65ad5 ("Staging: comedi: add comedi_bond driver") Cc: stable Reported-by: Wentao Liang Link: https://lore.kernel.org/lkml/20261103063301.1025860-1-vulab@iscas.ac.cn Signed-off-by: Ian Abbott Link: https://patch.msgid.link/20261103173610.89687-1-abbotti@mev.co.uk Signed-off-by: Greg Kroah-Hartman (cherry picked from commit fa0858523f07f8dd71d89b221f4422c3b8096d90) Signed-off-by: Ian Abbott Signed-off-by: Sasha Levin --- drivers/comedi/drivers/comedi_bond.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/comedi/drivers/comedi_bond.c b/drivers/comedi/drivers/comedi_bond.c index 78c39fa841776..076aecae2c776 100644 --- a/drivers/comedi/drivers/comedi_bond.c +++ b/drivers/comedi/drivers/comedi_bond.c @@ -182,7 +182,9 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it) char file[sizeof("/dev/comediXXXXXX")]; int minor = it->options[i]; struct comedi_device *d; - int sdev = -1, nchans; + int sdev = -1; + int nchans; + int nope = 1; struct bonded_device *bdev; struct bonded_device **devs; @@ -221,11 +223,14 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it) dev_err(dev->class_dev, "comedi_get_n_channels() returned %d on minor %u subdev %d!\n", nchans, minor, sdev); - return -EINVAL; + nope = -EINVAL; + break; } bdev = kmalloc(sizeof(*bdev), GFP_KERNEL); - if (!bdev) - return -ENOMEM; + if (!bdev) { + nope = -ENOMEM; + break; + } bdev->dev = d; bdev->minor = minor; @@ -246,10 +251,12 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it) dev_err(dev->class_dev, "Could not allocate memory. Out of memory?\n"); kfree(bdev); - return -ENOMEM; + nope = -ENOMEM; + break; } devpriv->devs = devs; devpriv->devs[devpriv->ndevs++] = bdev; + nope = 0; /* keeps the device open */ { /* Append dev:subdev to devpriv->name */ char buf[20]; @@ -260,6 +267,13 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it) sizeof(devpriv->name)); } } + + if (nope) { + /* Opened device cannot be used, so close it. */ + comedi_close(d); + if (nope < 0) + return nope; + } } if (!devpriv->nchans) { -- 2.53.0