Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1190921pxb; Fri, 1 Oct 2021 05:38:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgZVfJF7obMulRVmFw7pS6B3LKNyVY++c7vCTyw4MJpPITAG3yh2AdxKwETo0B2R0co6BI X-Received: by 2002:a17:907:7848:: with SMTP id lb8mr5922278ejc.494.1633091919234; Fri, 01 Oct 2021 05:38:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633091919; cv=none; d=google.com; s=arc-20160816; b=BXlvjyCrwLu0Q15KRlMlb81HRTKI6mdTXQK92k5t4Qm3O37GnqAGcbbzgPqTIRqsnZ IMBoveTGT6dGEGEPodH4XnA+0EfGI9jz4zC1lt2DWnOGRU2/E7N3zyX3pA6FXYXXgk50 JACRIrDb3Trl62lvGv9wR9HMpexhZWBtrnPnHbIeQ0dfHxDfmNoa10CzfBOcf63Py1hz y61sfDrQgR3M2nzYRlXtl8024VSVeyLty14TjHygdc4OIQ3EMFlkAtagWblMV3SsxcpU QBH8PATtcsY/Cvjyv85Oha5DFCNDMmqNyLFBT2ISXbGlVwxUwgfpRoYNszoREtOjcBQh hjAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=aHjvV9mnxGp/kUWJpaCXnDNEtGIT65+DfytQgVf0NOo=; b=mPYRhh625fuOi743zOELxehQtlpthz2XrywnvLz3a57PNGfSpvlXdEXfpp8y+ylmQM nY8JbiIenGjtHqWplHv83YMlOb+ZEyuGaZ4nsa9j3AS/QTK9PYA+3/vL/dWGq8GZ7G5m 3rNVkgvzB+gdgIxXHjN/DJg54+qsSbMUmBvbtCWuwgt2MNQPlrPyyF/OJKgOHvEyfVSC A34ydCJ8o0yefgc8fgw19YJPsSEQ5je57LctGmi4zRWJVyjH7W5ch9/YWnMzLN87AY8w JbVe75D21TSLAGg0bZe0DkLDVmZFH4pNg0sRQlSM8EVn4dBUaO5hqzydMa3qagozE4ap DNhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="CEFUt//w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t13si5504221edd.51.2021.10.01.05.38.06; Fri, 01 Oct 2021 05:38:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="CEFUt//w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353852AbhJALba (ORCPT + 99 others); Fri, 1 Oct 2021 07:31:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:33990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353865AbhJALba (ORCPT ); Fri, 1 Oct 2021 07:31:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 20BE360EBD; Fri, 1 Oct 2021 11:29:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633087785; bh=AOesFciQFfqDQGdIEvwsqkxbyxwJeoyuNHwKVFmlXTw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CEFUt//w51BGtH8mXtgvC3OzuQ1ev0Lx2QYUAumKwZPK8Gc8Bj44+kbreBUoKmM96 6GAXqe/0X9FQx+gZwzCSCAW4839Om4mmzyHBzGPmjEgkysUb/cT4Gv9ikI+/l4AlRA HIaztO5U58IOPrUn5s8DY4qnvwZ6bTdCLhc9orOw= Date: Fri, 1 Oct 2021 13:29:42 +0200 From: Greg KH To: "David E. Box" Cc: lee.jones@linaro.org, hdegoede@redhat.com, mgross@linux.intel.com, bhelgaas@google.com, andriy.shevchenko@linux.intel.com, srinivas.pandruvada@intel.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-pci@vger.kernel.org Subject: Re: [PATCH 5/5] platform/x86: Add Intel Software Defined Silicon driver Message-ID: References: <20211001012815.1999501-1-david.e.box@linux.intel.com> <20211001012815.1999501-6-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 01, 2021 at 03:38:23AM -0700, David E. Box wrote: > On Fri, 2021-10-01 at 09:14 +0200, Greg KH wrote: > > On Thu, Sep 30, 2021 at 06:28:15PM -0700, David E. Box wrote: > > > +static int sdsi_device_open(struct inode *inode, struct file *file) > > > +{ > > > +???????struct miscdevice *miscdev = file->private_data; > > > + > > > +???????get_device(miscdev->this_device); > > > > Why do you think this is needed?? Shouldn't the misc core handle all of > > this for you already? > > > > > + > > > +???????return 0; > > > +} > > > + > > > +static int sdsi_device_release(struct inode *inode, struct file *file) > > > +{ > > > + > > > +???????struct miscdevice *miscdev = file->private_data; > > > +???????struct sdsi_priv *priv = to_sdsi_priv(miscdev); > > > + > > > +???????if (priv->akc_owner == file) > > > +???????????????priv->akc_owner = NULL; > > > > Why is this needed? > > > > > + > > > +???????put_device(miscdev->this_device); > > > > I see this matches the open call, but if you do not have this in the > > open call, is it needed here as well? > > > > > +???????ret = devm_add_action_or_reset(priv->miscdev.this_device, sdsi_miscdev_remove, priv); > > > +???????if (ret) > > > +???????????????goto deregister_misc; > > > > I think this is all you need to clean up your device memory, not the > > get/put device in open/release, right? > > It does clean up the memory, but it does so immediately after the device has been unregistered, even > if a file is open. The get/put ensures that if files are open, the memory isn't cleaned up until the > files are closed. > > I can show that this happens without the get/put, > > open() > unbind device -> devm action called -> kfree(priv) > ioctl() -> priv accessed > > but it doesn't blow up. I guess because the former location of priv is accessible by container_of on > the miscdev. But that memory was freed right? You are dealing with two different structures with two different lifecycles and reference counts. Yes, you can kind of try to tie them together here, but really, that way lies madness. Why not just drop the misc device entirely and only use the struct device that the kernel created for you? That would make everything much simpler. thanks, greg k-h