Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5813791pxb; Tue, 16 Feb 2021 08:13:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMiba0uwqXQgrKnsHvCHZ+m+uiwjaGiHUp5VTcxkNrIkzFb2RrMFhQ9ePro4S2a5nZFRV8 X-Received: by 2002:aa7:d8da:: with SMTP id k26mr21802721eds.364.1613491980739; Tue, 16 Feb 2021 08:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613491980; cv=none; d=google.com; s=arc-20160816; b=UcVeVPm4dfdra45Gi2vXdH0mK1/BpzxOXvHOYFY2TFENzc/lSsbCPkwxwasGMZOJZP KmWh19uV/WayQDIttd2JzsaIJpFiCHomtO7OAuE+K7Mp4bqVom7VN8OI64qblm1oCOtx ab3PUzlJGl2IjjTMiV5fS7B3rLzrBf6QUhLuMqI7W9Ehz4CTnqOFfYa6q4p3v1vt65dw qrlM9bNG1oeP7c04VhlpGFvcp0Nm6w2J4rXZmYLjZY+KLRLD8gOMlClY8+tlV4V9xUDw q4zM0JeGhSoVo2sfu3gUbL3mHxGcefQ+PZZBHDd/HS5FXoHPROjKKF+C5ysUa1rpWwcl ccoQ== 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=qk8irXqWkRBS6eeiOmv/Vo75rhJ1iwOeRypXYRQFZT8=; b=kSVvPzisAE5W8g0v6OxKslcCzJhkVAFxoHbVklFepa9ec0VUcMpFDO1kLFSRjN2E2a bExyV6mDTNXBwyNekpqu2b0gJlItyOIgOA5AaN9SM0/U8ZAPL2I6dqcTqip0CnNCRKEd PIMIVoNhyiOonstiLmUSsXXaVGaGbAWlxNuhcdj+4D3MkF/jHdYuLYUEMrWvtDVl/jkj 9MT7DFwJOEcs0oqWDFPndSgIE/tzVbSxffLef5V4ZKNaIoaMpEffaAk/BI7hvsn7SFlH nNjxGmOcjy1F30yKGo+koIud2XMwQLJ9khCsqhT/8OTKOMN/ZEd4jormoCmlUFhneb1k bc1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QxCPMsdi; 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 m5si8897840ejk.585.2021.02.16.08.12.28; Tue, 16 Feb 2021 08:13:00 -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=QxCPMsdi; 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 S230438AbhBPQKy (ORCPT + 99 others); Tue, 16 Feb 2021 11:10:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:49988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230131AbhBPQKk (ORCPT ); Tue, 16 Feb 2021 11:10:40 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2F33464DE0; Tue, 16 Feb 2021 16:09:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1613491799; bh=T8z4FJ8TFARXixQ5KCdrCvlpeBamrvRhdKdPYXzvLf0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QxCPMsdiP1kSav4wMJzVNPCLGSNTuI0geryHe+g8JYhS/hn8fu3EPwx8V9KH6FHGP K8YO3v4ArJszGPImvrUUMGrX08Ifqr4Luw34L+utjp4ZvvQ1FPQqm4L0/vGFq+c12n aDSpR9Zhzm1/7dDzpEKeEPhvVT0t3QAYTvcOT4lPDJfo4Znu4dv4O756Be6khtwERL qgjiAmfX+7lc0kqaOYp/uLePcb9y29ve7hTBgy3AnL4mS7LxPWqfwH1a4A6WJVjHeM Adjo0wby5B54ooOgaJEa9Tzzu5hReWX+cqoifFL9L0GlJEpo8dgcJr3Std5Hvacg9M O55wy2f48uchA== Date: Tue, 16 Feb 2021 18:09:47 +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: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. > > > +{ > > > + 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