From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B08FEC433DB for ; Tue, 16 Feb 2021 16:06:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D98A64DDA for ; Tue, 16 Feb 2021 16:06:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230202AbhBPQGQ (ORCPT ); Tue, 16 Feb 2021 11:06:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:49338 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230221AbhBPQFc (ORCPT ); Tue, 16 Feb 2021 11:05:32 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 679D064D9F; Tue, 16 Feb 2021 16:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1613491491; bh=z8NrUWd5TbVZgAg2HRWl/KOXL0/wZcaDM0wAN4DfoLE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MLywsHKHdAVaj8YuJrWT0XGGerCvVWPJiExCtVVmcVSjy6cUzdc/Go5X3eGyxlkJD s0XWGvet/nk/Tpq2Pf885GcmXoGr05w7p387dru8Xsq4bqNLeGd8HmiUTOVAKYOi+6 MAm/GlFetanh4nPjcNV7ux79/yoWxi/+lWtnyt/nj2s+wJVWqgRksRi05aTu8dGF+b NworuHFIoUbZdduZVVcEyPPOnmX1VaQFU4foTyrMKYnZk0h8TFz1HIo+JvLRTMv8xp P9byXBcYMZLBrCAE9sS4PfTOWqytn+JBbtmD2Ye40j2yC9gSxi4BoQN6xCbu/eNeeW ALN/k8vvDMGRQ== Date: Tue, 16 Feb 2021 18:04:39 +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: <20210216125342.GU4718@ziepe.ca> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > +{ > > + 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