Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5814414pxb; Tue, 16 Feb 2021 08:13:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3EYkfifVg3bHvWvDGj/eJxauLY4b2Av5miSPRquCaffbx4w2x/PfPJiyPs0tb7AUWORMV X-Received: by 2002:a17:906:7c4f:: with SMTP id g15mr2245757ejp.184.1613492031863; Tue, 16 Feb 2021 08:13:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613492031; cv=none; d=google.com; s=arc-20160816; b=MBKbEqZhiQ19w7R+v97nSqUleQNWJoz0yQbjAXEP9gsdzbChs58U2lv0tiyy447zF2 Fc2ks71WKHxCOaYKTx0Qd6hZYUSan5w3ulLuWqm7RLKf0nROZL03xF/5DNkvb5Y8W3hH khUJF1IT2+o4CoCoZntNXrNg+iLLErsnad0RPN3DZ2RvsvC3BL3LBBS0AS3SZcWHPXrN mvgwqXOtLk5gw8jZ3h6Lci2ak9VsZFpF27H4ZBa/XgGMAzypRXugkiO/I8tv4eHReKUt 6906K+ur4wmEry5d135ZOmQQVk4SQ/uC84tdMB2PAsnKPmVELtbEZPGfN/u/DD+/AAZe pq5Q== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Tco54G+S4DfMRvU/GhrW1RdhOEqtNfaqDThTKX7eEM0=; b=GqC73ruNpToPG+3Wr2UPpKBcECCxnqW3ucANsQnrwcdQQoRRORmv0hsGbSMdAUXZrU zo7QkKXYA8OtEyJputKfKMZYLy4UFsKc5ChkmCU9yk9zHyg1JMyu6VytP2v9OhstmhHl tLnYLq0X6KKE0mgTWpyWL/T5/nJC+ryAeO5H7bHkuhAWZM3d9p0psXLiwA4U3WiEgp2P P2sO+3TXNH/V2xFGZ0VKgRvuUk2eCdQ4ZfZPMx4rvsvLMHAeX7R4C26TO2JC9rb3wR70 WIvOFWZd2+PcV48w6c/aL8WtCtfRCeugtiqxhVQG0KHfoz5cveYQLsopl6/zoMMb+SJf h6VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SNneJQvQ; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 88si738346edr.198.2021.02.16.08.13.28; Tue, 16 Feb 2021 08:13:51 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=SNneJQvQ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230482AbhBPQMG (ORCPT + 99 others); Tue, 16 Feb 2021 11:12:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:50230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbhBPQLz (ORCPT ); Tue, 16 Feb 2021 11:11:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3013164DF0; Tue, 16 Feb 2021 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1613491874; bh=BnAwcr4oeUbABUoa/t/lY4qqMdgd+TgxOOqMjppumfQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SNneJQvQTK0Y5P+nVLp13bNH6IsnsFwcfMK+gdG3kcSC5gYF7q2UhuDZgf3VSGwWq bh3of2l440ECX6dhSrrtcDC9AvBehFUoFgXQklIB/5TZ47d0udcABU1KugyIqQHbaH o7hs925+0VTZljLrWe3DhLCWI10+0AGwVirTDRZaIAKO5UxOl23E+27BvTbLQHXy68 6S/n5vRS67HBCqSFk3s7tlCQKzjqaiPl6Sln3ljiDduxzxTvPQVu1ucB5LXyEz+YMc NknEjR0SSS4Oea2qW/27/FtxVmvXZiAbZOv1OWCDUDMrEyvxSPv/lqVKtwbb6gcE6J 4rdevL1XLWV6A== Date: Tue, 16 Feb 2021 18:11:02 +0200 From: Jarkko Sakkinen To: Jason Gunthorpe Cc: Lino Sanfilippo , peterhuewe@gmx.de, stefanb@linux.vnet.ibm.com, James.Bottomley@hansenpartnership.com, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, Lino Sanfilippo , stable@vger.kernel.org Subject: Re: [PATCH v4] tpm: fix reference counting for struct tpm_chip Message-ID: References: <1613435460-4377-1-git-send-email-LinoSanfilippo@gmx.de> <1613435460-4377-2-git-send-email-LinoSanfilippo@gmx.de> <20210216125342.GU4718@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 16, 2021 at 06:09:50PM +0200, Jarkko Sakkinen wrote: > On Tue, Feb 16, 2021 at 06:04:42PM +0200, Jarkko Sakkinen wrote: > > On Tue, Feb 16, 2021 at 08:53:42AM -0400, Jason Gunthorpe wrote: > > > On Tue, Feb 16, 2021 at 01:31:00AM +0100, Lino Sanfilippo wrote: > > > > > > > > +static int tpm_add_tpm2_char_device(struct tpm_chip *chip) > > > > BTW, this naming is crap. > > > > - 2x tpm > > - char is useless > > > > -> tpm2_add_device > > Actually, tpm2s_add_device() add put it to tpm2-space.c. No, tpms_add_device() :-) (sorry) /Jarkko > > > > > +{ > > > > + int rc; > > > > + > > > > + device_initialize(&chip->devs); > > > > + chip->devs.parent = chip->dev.parent; > > > > + chip->devs.class = tpmrm_class; > > > > + > > > > + rc = dev_set_name(&chip->devs, "tpmrm%d", chip->dev_num); > > > > + if (rc) > > > > + goto out_put_devs; > > > > Right, and empty line missing here. > > > > > > + /* > > > > + * get extra reference on main device to hold on behalf of devs. > > > > + * This holds the chip structure while cdevs is in use. The > > > > + * corresponding put is in the tpm_devs_release. > > > > + */ > > > > + get_device(&chip->dev); > > > > + chip->devs.release = tpm_devs_release; > > > > + chip->devs.devt = > > > > + MKDEV(MAJOR(tpm_devt), chip->dev_num + TPM_NUM_DEVICES); > > > > Isn't this less than 100 chars? > > > > > > + cdev_init(&chip->cdevs, &tpmrm_fops); > > > > + chip->cdevs.owner = THIS_MODULE; > > > > + > > > > + rc = cdev_device_add(&chip->cdevs, &chip->devs); > > > > + if (rc) { > > > > + dev_err(&chip->devs, > > > > + "unable to cdev_device_add() %s, major %d, minor %d, err=%d\n", > > > > + dev_name(&chip->devs), MAJOR(chip->devs.devt), > > > > + MINOR(chip->devs.devt), rc); > > > > + goto out_put_devs; > > > > + } > > > > + > > > > + return 0; > > > > + > > > > +out_put_devs: > > > > + put_device(&chip->devs); > > > > > > I'd rather you organize this so chip->devs.release and the get_device > > > is always sent instead of having the possiblity for a put_device that > > > doesn't call release > > > > /Jarkko