Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp511222imm; Wed, 13 Jun 2018 04:14:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIZk5ClTOprEb3jLxJdns1Bw46W+4wgI9E3LNnmDcLe+1rHMD3avF+xqvagnF6PH/UQy99g X-Received: by 2002:a63:7211:: with SMTP id n17-v6mr3627249pgc.94.1528888497341; Wed, 13 Jun 2018 04:14:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528888497; cv=none; d=google.com; s=arc-20160816; b=w6oGdGBCRKBSg46li9q4OrtQslwyJWkunQPvOYaHGQ0iF5HQOqRyh3rq8saW/nuUb8 f1Vo00+hakcH6r4/oF5ZyfTrFytJ2paZ/k2blquZtctZKwuLfUXT3I33/Hpn29BekjqY +VjAFDKn3SxrV5etRus2cKfUvgm3TfaTNa2cPeQ6KgML4slq5q/jupOYH79pFzK2HYpA TDL7zxdj9Fl+d3wYPVkQmARBKliFFGv2UccDtiai2u9Min5xxN9fGlZwpapgMfuOWanM /5CU0ebHPv9BZq74OL1XKRVgODD131ntdpjab6nMN7+doBtKvHJtT6oUSX+2B9fXEu/Y AkaA== 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:arc-authentication-results; bh=4nC7y+nzyPWHgl12C9Xo0stNvarbJy4N5pTtFFDn058=; b=jrP8jsPR2zhcq9icWxNovGiOIIh0vvtiZmHgEzJnWmCmd4m6Q4+mvfyI3WRoVoigqb KEqg73mc+LONGoiH50TS12g9GYjbLKg0SdMMz4kixVa7gvPboVloNvG5JZIp2Asv3ya+ fANbMgHkywSVqGeLQVt0CH1hZ1m9MkuNLsJm3BnHcrMx1mIpvDPxtotO0+rRgv/UEnBU mGGXVG2l6GOdcQn2APSyA910WBuQPwqWEXGFeqY9wTjOauqgV5xGuVwRQcKU9gVsSyc0 UNQf4JOAGnZTpAmDYME/021+My0FTrDFxVh5aOuGNQLNv95mNANPb9vDUHPppE+9rVtW TATw== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c18-v6si2671594pls.407.2018.06.13.04.14.43; Wed, 13 Jun 2018 04:14:57 -0700 (PDT) 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935328AbeFMLON (ORCPT + 99 others); Wed, 13 Jun 2018 07:14:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55214 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934677AbeFMLOL (ORCPT ); Wed, 13 Jun 2018 07:14:11 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF62987A82; Wed, 13 Jun 2018 11:14:10 +0000 (UTC) Received: from gondolin (dhcp-192-215.str.redhat.com [10.33.192.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B3741C5BC; Wed, 13 Jun 2018 11:14:05 +0000 (UTC) Date: Wed, 13 Jun 2018 13:14:02 +0200 From: Cornelia Huck To: Pierre Morel Cc: Tony Krowiak , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, freude@de.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, borntraeger@de.ibm.com, kwankhede@nvidia.com, bjsdjshi@linux.vnet.ibm.com, pbonzini@redhat.com, alex.williamson@redhat.com, pmorel@linux.vnet.ibm.com, alifm@linux.vnet.ibm.com, mjrosato@linux.vnet.ibm.com, jjherne@linux.vnet.ibm.com, thuth@redhat.com, pasic@linux.vnet.ibm.com, berrange@redhat.com, fiuczy@linux.vnet.ibm.com, buendgen@de.ibm.com Subject: Re: [PATCH v5 04/13] s390: vfio-ap: base implementation of VFIO AP device driver Message-ID: <20180613131402.0305d092.cohuck@redhat.com> In-Reply-To: <41e7ccbd-f6f5-ba20-f236-7824c682994d@linux.ibm.com> References: <1525705912-12815-1-git-send-email-akrowiak@linux.vnet.ibm.com> <1525705912-12815-5-git-send-email-akrowiak@linux.vnet.ibm.com> <889b8d41-e08c-0eb5-2de0-a1d6669a03b3@linux.ibm.com> <20180613094812.1fd1846d.cohuck@redhat.com> <41e7ccbd-f6f5-ba20-f236-7824c682994d@linux.ibm.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 13 Jun 2018 11:14:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 13 Jun 2018 11:14:10 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'cohuck@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 13 Jun 2018 12:54:40 +0200 Pierre Morel wrote: > On 13/06/2018 09:48, Cornelia Huck wrote: > > On Wed, 13 Jun 2018 09:41:16 +0200 > > Pierre Morel wrote: > > > >> On 07/05/2018 17:11, Tony Krowiak wrote: > >>> Introduces a new AP device driver. This device driver > >>> is built on the VFIO mediated device framework. The framework > >>> provides sysfs interfaces that facilitate passthrough > >>> access by guests to devices installed on the linux host. > >> ...snip... > >> > >>> +static int vfio_ap_matrix_dev_create(void) > >>> +{ > >>> + int ret; > >>> + > >>> + vfio_ap_root_device = root_device_register(VFIO_AP_ROOT_NAME); > >>> + > >>> + if (IS_ERR(vfio_ap_root_device)) { > >>> + ret = PTR_ERR(vfio_ap_root_device); > >>> + goto done; > >>> + } > >>> + > >>> + ap_matrix = kzalloc(sizeof(*ap_matrix), GFP_KERNEL); > >>> + if (!ap_matrix) { > >>> + ret = -ENOMEM; > >>> + goto matrix_alloc_err; > >>> + } > >>> + > >>> + ap_matrix->device.type = &vfio_ap_dev_type; > >>> + dev_set_name(&ap_matrix->device, "%s", VFIO_AP_DEV_NAME); > >>> + ap_matrix->device.parent = vfio_ap_root_device; > >>> + ap_matrix->device.release = vfio_ap_matrix_dev_release; > >>> + ap_matrix->device.driver = &vfio_ap_drv.driver; > >>> + > >>> + ret = device_register(&ap_matrix->device); > >>> + if (ret) > >>> + goto matrix_reg_err; > >>> + > >>> + goto done; > >>> + > >>> +matrix_reg_err: > >>> + put_device(&ap_matrix->device); > >> Did not see this before but here you certainly want to > >> do a kfree and not a put_device. > > No, this must not be a kfree. Once you've tried to register something > > embedding a struct device with the driver core, you need to use > > put_device, as another path may have acquired a reference, even if > > registering ultimately failed. See the comment for device_register(). > > IOW, the code is correct. > > learned something again :) , > but still, a kfree is needed for the kzalloc. > Does'nt it? No, the put callback for the embedding structure needs to take care of freeing things. Otherwise it is buggy. > > > > >> > >> > >>> + > >>> +matrix_alloc_err: > >>> + root_device_unregister(vfio_ap_root_device); > >>> + > >>> +done: > >>> + return ret; > >>> +} > >>> + > >>> +static void vfio_ap_matrix_dev_destroy(struct ap_matrix *ap_matrix) > >>> +{ > >>> + device_unregister(&ap_matrix->device); > >>> + root_device_unregister(vfio_ap_root_device); > >> Also here you need a kfree(ap_matrix) too . > > Same here. > > >