Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2328917ybv; Mon, 24 Feb 2020 03:23:16 -0800 (PST) X-Google-Smtp-Source: APXvYqzolB8wBQsmUoOCMknMIFqBVqvA2DU/Ud1irsBNFlXKu2+IANUggaOX1Qpm+5R1DI/NTPIo X-Received: by 2002:a05:6808:191:: with SMTP id w17mr11803224oic.29.1582543396215; Mon, 24 Feb 2020 03:23:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582543396; cv=none; d=google.com; s=arc-20160816; b=EoShTH46U260fuYm/EdgM5C5WTChuJVv5QWLsgFVFo0xXQao+JkUgPGpE+miVNKIsw SmkjktWVlGykwCIpaWzAGxKH3hw1YYm9x2VlBZBzkk90jnE4wEdjd65rOzBLIKYYqs0b Qr/QWw8Lf8cstC0FGiF2j1wPk6m6TgJeMQxe15dwuFSr6+ZidX7UFo75H+PC2ZoBxDa6 DL027L+Wbkd8JCWi0DhPhnxjbp/UKRpDV4Q8MAebi79aOiuly4dtcL0Yc5BEyiDiuEmo wx6VWpYsFhm0g6kxy4hpRxbSl69kln7lcgILzQ725U+oMwkF2DWX88BpShMsKFqOQgH7 6C7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=uIs4TQ9uC+N1F3YjmNZX6HJXn+8nFfqmhSVDIT65V9k=; b=OK/14MDSUM0hsLAEriGxJxdO9k70GDJfwi4LFGgdLgJoT8GlbWPOX70KCkq2oSF+W8 5bjpohtH5vVLbTteoAYjG+Bl/Bzn6R398B5n0z//ljA4NN9qSMTx9GrUNBnggTOvV3r9 hAeDLVKaTp7WG3t9KOkCw6c6eomOisd1A0aWkxXpel0Fp0Ovp8+1kFJ7ZbbfbH1LnM8z xJm7VBonuQQA6HLesTzVFvh/yWQYwDT9ZgeclYDT1iqcRdMBa8hmqN+lcV5dlUrlcPGd 12kJzhE8Ca7NPEAVai/j1j2WfO2Mb/HgnPwblYDqxerRf4m77sWYg95cVatLWli83YQL erVg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a22si5853873otp.84.2020.02.24.03.23.04; Mon, 24 Feb 2020 03:23:16 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727277AbgBXLWL (ORCPT + 99 others); Mon, 24 Feb 2020 06:22:11 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:54092 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726778AbgBXLWL (ORCPT ); Mon, 24 Feb 2020 06:22:11 -0500 Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 6730E29047B; Mon, 24 Feb 2020 11:22:09 +0000 (GMT) Date: Mon, 24 Feb 2020 12:22:06 +0100 From: Boris Brezillon To: Vitor Soares Cc: "linux-kernel@vger.kernel.org" , "linux-i3c@lists.infradead.org" , Jose Abreu , "corbet@lwn.net" , Joao Pinto , "arnd@arndb.de" , "wsa@the-dreams.de" , "gregkh@linuxfoundation.org" , "bbrezillon@kernel.org" , "broonie@kernel.org" Subject: Re: [PATCH v3 4/5] i3c: add i3cdev module to expose i3c dev in /dev Message-ID: <20200224122206.10984b3f@collabora.com> In-Reply-To: References: <20200221233216.3b2038f8@collabora.com> Organization: Collabora X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 24 Feb 2020 11:04:50 +0000 Vitor Soares wrote: > Hi Boris, > > From: Boris Brezillon > Date: Fri, Feb 21, 2020 at 22:32:16 > > > On Wed, 19 Feb 2020 01:20:42 +0100 > > Vitor Soares wrote: > > > > > +static int i3cdev_detach(struct device *dev, void *dummy) > > > +{ > > > + struct i3cdev_data *i3cdev; > > > + struct i3c_device *i3c; > > > + > > > + if (dev->type == &i3c_masterdev_type) > > > + return 0; > > > + > > > + i3c = dev_to_i3cdev(dev); > > > + > > > + i3cdev = i3cdev_get_drvdata(i3c); > > > + if (!i3cdev) > > > + return 0; > > > + > > > + /* Prevent transfers while cdev removal */ > > > + mutex_lock(&i3cdev->xfer_lock); > > > + cdev_del(&i3cdev->cdev); > > > > When cdev_del() returns there might be opened FDs pointing to your > > i3cdev [1] ... > > Yes, I know. I protected the driver part but I missed the > file->private_data. Not sure what you mean by protection, but if you meant locking, then it's not enough: you need to refcnt the struct if you want to prevent use-after-free situations. BTW, I had a closer look at the usbdev implementation, and maybe you should base yours on usb instead of i2c. They seem to register a cdev at module init time, and add a dev_t per device at device registration time. Not sure how they handle the userspace-driver vs kernel-driver concurrency, but maybe returning EACCES (or EBUSY) instead of detaching/attaching the i3cdev everytime a device is bound/unbound would be simpler. Also, I think Arnd was right, it'd be simpler if i3cdev support was integrated to the core (still left as a option so it can be disabled, but with a dedicated i3cdev field in i3c_device instead hijacking the driver private field).