Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1256715imm; Sun, 15 Jul 2018 03:19:09 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeudZiOt0AcURqxACqbyaSUVQzhtjE5yr3YOlEdt2H6j4xlM/Rdid5Y7jxdum0yZhuUyodD X-Received: by 2002:a62:e813:: with SMTP id c19-v6mr13805766pfi.124.1531649949627; Sun, 15 Jul 2018 03:19:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531649949; cv=none; d=google.com; s=arc-20160816; b=ZmafuLGTPPuLSUbklbLN11BRa4xI+fVeeQom/pnUGYIvJxvsO7tU8GuaxGfQ8ttnff ubYMIdMWZlFEYao3wAyLqMosJWUgzsxe7nKwFU/FZrahlSCs07zxbGPSxIoVAeWsBzDl xRi0JGXR2jSUVUgiJZ+HyeIvlFegRwwJpx0W1+9iQWyLwzmHVl5SMugou7WkeDMe4FTS eloVi5NKxQh/9lNwSCZaXiQaUtKZnNWU0mu730uKJgEZUk4Gfkgw4wRC4IUvQgdQ7Ghp zVvbDDbJXq4VI/D/z3oRw519kNc1ktrmmsPAI3RtIYaGRcsFQu0H1zzkcCQYGQPDd84t QZTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=ACK/c6UUuncJo62TVbwW6/DMIGe7BZnMYMz2rZstmxE=; b=YZEppCIu2hVJ2/Nxf0FytTJeOlHQnjdQQHenlOEGHdcBzGOAg+E1tcBMALD98QMUjP iiTs+O0Be46FTaJqiebOCgluZEk3yiIArQ3/07R4PHNDCEYIu4S8v8ZMJDv310fNlmUD blISZomoR5sHOylikGeo+2NFXuRA2c9DF5NZOz0eOdmVk+lo+poYiXA7O8zYGH1P1MH6 32EZ8DBvGEDIvmeBTIQI4D9l2mjhcC2naWbVxKWrQ967e+vqafd0vmYfY59P+muOK1n5 jHMJIwm/8tLvpxF65+Kqlur8twELihrXhMHOvVM31ymfSb0/678bzZXT4zA5/+7yEdwE qH3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bQK63Zz+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7-v6si25873181pgs.35.2018.07.15.03.18.55; Sun, 15 Jul 2018 03:19:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bQK63Zz+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726147AbeGOKkt (ORCPT + 99 others); Sun, 15 Jul 2018 06:40:49 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45405 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726030AbeGOKkt (ORCPT ); Sun, 15 Jul 2018 06:40:49 -0400 Received: by mail-wr1-f66.google.com with SMTP id c4-v6so16366611wrs.12; Sun, 15 Jul 2018 03:18:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ACK/c6UUuncJo62TVbwW6/DMIGe7BZnMYMz2rZstmxE=; b=bQK63Zz+arbg7eVQqpGuOClT+TNqvzkRR5oNXbQLPzrcPQEmOuKh1kJ7t++T4QF7fL XGg8ZZNG4JZh+A0hJRyIOrQFnT1EWxANAH3XWR3f/FRRduLvuucdSiuZ8n/snl3gPDEp SNFRRD8JfGxo0vqa+oH1wFNvj9aVhMmFCaeSPYTqMiIkdwXypgzpGOP8krwcoOLysyzy 2Uz/s2rxvdUqsbTP/qYY9wpWsvOGc2jJ2KE2DwkUhLnICcv7MdtneSgwW71YNwMxbtkP BZd1zwABWFPQHPr90K2BOKp9S473AwEnAvvw8ZouY76e3AeZcDI3fbHe50Qdui5npiVi /AFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ACK/c6UUuncJo62TVbwW6/DMIGe7BZnMYMz2rZstmxE=; b=s0Zn5zf9bCFSZNuPstbA31X63aCuFbeYkzMONidehdDLjC3qJI6xeib+79Ht7xFhvf 839D+IPzo6RkkTjw9NlJhhupf1jouu3/ku3PXtip57Zuf4670GAIH9sY5qffN0Znfi6j JBaiO2r6rm5xtSBzhNxz4xmnFnSiEZ6CgRLm/HOhgxDjZ63xV0O3RK0wWNz2o79OoKEA TXTZOTUduL8jlbNmn818kvGNutaGRV2TsaaMJEY7mqdL3Aiz1EBT5C+M4IbAT9OcJO6U 1n0oYvZO1155q09PZ2PfZD4l7By0E/pNix+fTvyCMh5jAM4L0S7nihgW+Ailzk7BNEuk +n8A== X-Gm-Message-State: AOUpUlE+1vapdpF1LPo2JgLcqOpDJ6pfBzSAdUZ2CJ4eUcShtP2Bon3n IsoCVNJlXjc5Luik9jdvXDo= X-Received: by 2002:adf:e9c1:: with SMTP id l1-v6mr8996332wrn.14.1531649899708; Sun, 15 Jul 2018 03:18:19 -0700 (PDT) Received: from localhost ([195.46.23.67]) by smtp.gmail.com with ESMTPSA id g15-v6sm21909285wrh.48.2018.07.15.03.18.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 15 Jul 2018 03:18:18 -0700 (PDT) Date: Sun, 15 Jul 2018 10:18:15 +0000 From: Dmitry Torokhov To: Greg Kroah-Hartman Cc: Marcus Folkesson , Alexey Khoroshilov , "linux-input@vger.kernel.org" , lkml , ldv-project@linuxtesting.org Subject: Re: [PATCH] Input: pxrc - fix leak of usb_device Message-ID: <20180715101815.5derw7zfjm2d2ayn@penguin> References: <1531512477-31981-1-git-send-email-khoroshilov@ispras.ru> <20180714080920.GA15123@gmail.com> <20180714085109.mbhk6aybpjsbuq6l@penguin> <20180715074225.GB15123@gmail.com> <20180715101244.GA32410@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180715101244.GA32410@kroah.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 15, 2018 at 12:12:44PM +0200, Greg Kroah-Hartman wrote: > On Sun, Jul 15, 2018 at 01:06:32PM +0300, Dmitry Torokhov wrote: > > On Sun, Jul 15, 2018 at 10:42 AM Marcus Folkesson > > wrote: > > > > > > On Sat, Jul 14, 2018 at 08:51:09AM +0000, Dmitry Torokhov wrote: > > > > On Sat, Jul 14, 2018 at 10:09:20AM +0200, Marcus Folkesson wrote: > > > > > Hi Alexey, > > > > > > > > > > Good catch! > > > > > > > > > > On Fri, Jul 13, 2018 at 11:07:57PM +0300, Alexey Khoroshilov wrote: > > > > > > pxrc_probe() calls usb_get_dev(), but there is no usb_put_dev() > > > > > > anywhere in the driver. > > > > > > > > > > > > The patch adds one to error handling code and to pxrc_disconnect(). > > > > > > > > > > > > Found by Linux Driver Verification project (linuxtesting.org). > > > > > > > > > > > > Signed-off-by: Alexey Khoroshilov > > > > > > > > > > Reviewed-by: Marcus Folkesson > > > > > > > > Hmm, the biggest question however if we need to "take" the device, as I > > > > do not think interface can outlive the device, and whether we actually > > > > need to store it in pxrc, as we only need it during set up, as far as I > > > > can see. > > > > > > Yep, the device is only used during setup. > > > I interpret the comments for usb_get_dev() as you should take a > > > reference count on the device even if you only use the interface, but I > > > could be wrong. > > > > > > From usb_get_dev():: > > > > > > * usb_get_dev - increments the reference count of the usb device structure > > > * @dev: the device being referenced > > > * > > > * Each live reference to a device should be refcounted. > > > * > > > * Drivers for USB interfaces should normally record such references in > > > * their probe() methods, when they bind to an interface, and release > > > * them by calling usb_put_dev(), in their disconnect() methods. > > > > Hmm, usb device is a parent of usb interface so our driver model rules > > ensure that usb device should not disappear while interface device is > > still there. Greg, is this comment still valid? > > Yes, that is true. But remember that interface devices can go away > while the parent is still present, so if you need the interface pointer, > you have to grab a reference on it. But not in a simple interface driver, as we'll unbind the driver before destroying the interface... IOW we need to record the reference only if we are doing something unusual. Thanks. -- Dmitry