Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp987000imm; Wed, 11 Jul 2018 14:52:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcUZ1YOXr9H7VlcI3+QH6HsuFnI5sd0331FaCQuMSMFMMhJT6T5wIN8c2sBuoCBtMC2Kdp6 X-Received: by 2002:a65:64d7:: with SMTP id t23-v6mr306164pgv.207.1531345930568; Wed, 11 Jul 2018 14:52:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531345930; cv=none; d=google.com; s=arc-20160816; b=a5y9QVJ9lyLVzCpB9I8SYD0BdIGIIz1hdlgMtP4G+Ix9SjwIZClI1jvLhyNFZzS82o nqz8CsxTA7bNKiMgeliy3AGUC8K4ZrYHwIpZTOsXva9rVr9otCnBWndnVA43g7AQ1ove fyv7sOBHde9d4k0eyiXdvC0SxpEvsX4XfnrC8v8MiakEv3p0aL2dJQgUGQrr/zwS7GRq rZMq8VEQnttZe8fhfCTps7H7AGDidFjYyewAnF+GW8crKetrcXnrplcuKYuDXmGu6F7c 8tRuoqczvYZ9Silsfo2ROLa+NT5ED7lGqDshZTkUHSyG0nd3Q0/rh604Fzf9CfhZR9eB AYbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=CrgWWg9qYRVEe5gOFRQ/yPP+tcvktBjiwiDmbsOBgC0=; b=kr9M+NuKhaIGTFZW720M2M+gRh0JoDjzsGyU0HHKiBI2UkIpube3XNmNI2/hMirEhK j4vSDqbVfmhaOkI/0LeT1pSLc2Sq5CHk2Dh8Q7+u5mT+J5EsDBBoGewto6Q1RdlzZ3ET dK0hMHIhQZry7XEISPGQDuo2xMJRKFBk/s2FmLZQNqpLyKqQNSp0mnaLDx6Qxk3BtRwi RAtCsT6MkpYfIhC2AfBNFcIPESzS3Iy5Pa8z3+9bUgENRoZtpkJUPf/UuLREbd/w7CGW fymEXdHqJ1CZG5YVplcpjznqf5ric8g4MqDNW/2QJgsV/59/Eel9XubZXDLrnzm0bt4n 9gqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=swTZh0uu; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a33-v6si19839699pld.167.2018.07.11.14.51.55; Wed, 11 Jul 2018 14:52:10 -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; dkim=pass header.i=@kernel.org header.s=default header.b=swTZh0uu; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732398AbeGKQEn (ORCPT + 99 others); Wed, 11 Jul 2018 12:04:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:37254 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726429AbeGKQEm (ORCPT ); Wed, 11 Jul 2018 12:04:42 -0400 Received: from mail-yw0-f174.google.com (mail-yw0-f174.google.com [209.85.161.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1E32D20C0B; Wed, 11 Jul 2018 15:59:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1531324783; bh=yuJtATNcTluX0YYvzolm37e7lk3R3Jk4xIGag1bxLyc=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=swTZh0uuPa7OkI7if6b8FtidNNCLEtitjkF/Cegl8+HoLRQ1wBZl16fc3Sh1fnVxW u00udz7pIb/HNdGeqUzkmpZ54zKapd54BYHTai/tPKz5D9TCscLaIgCd+BPWs+Qk9W utZE/A/pb/haFfMneYnPgQx7kTJvVYVO54numuu0= Received: by mail-yw0-f174.google.com with SMTP id q129-v6so6520862ywg.8; Wed, 11 Jul 2018 08:59:43 -0700 (PDT) X-Gm-Message-State: APt69E1Rtfn4CcPle3vP2dd184pDrhERi75i65R4+TUaQmgo+JL4PC0D Lh05UWoUqiiz4kjs71AseenZJjdh62dlU2adoSg= X-Received: by 2002:a81:a348:: with SMTP id a69-v6mr12202243ywh.142.1531324782340; Wed, 11 Jul 2018 08:59:42 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:8182:0:0:0:0:0 with HTTP; Wed, 11 Jul 2018 08:59:01 -0700 (PDT) In-Reply-To: <5553262.evi6GU8epL@pcbe13614> References: <5553262.evi6GU8epL@pcbe13614> From: Alan Tull Date: Wed, 11 Jul 2018 10:59:01 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: fpga: fpga_mgr_free usage To: federico.vaga@cern.ch Cc: linux-fpga@vger.kernel.org, linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 11, 2018 at 7:38 AM, Federico Vaga wrote: Hi Federico, > Hi Alan, > > I have another point that I would like to discuss. It is about the > usage of 'fpga_mgr_free()' which does not look like consistent. > > This function, according to the current implementation, can be used by > an FPGA manager user and it is used by the FPGA manager itself on > device release. This means that the user can only use this function if > fpga_mgr_register() fails (to clean up), otherwise the user must NOT > use this function, otherwise we most likely get an oops (NULL or > invalid pointer). The example here is correct, this is what we should > do: > > https://www.kernel.org/doc/html/latest/driver-api/fpga/fpga-mgr.html > > But I suggest to document it better or prevent this type of mistakes > from happening. Following a couple of proposals > > ------ > 1. > Document it better. This is easy, in the fpga_mgr_free() kernel-doc > comment we explain that the use of this function must be limited to > clean up the memory on a registration failure. If an FPGA manager has > been successfully registered then it will be freed by the framework > itself. > > But still, this does not prevent an oops from happening. > ------ > 2. > Remove the fpga_mgr_free() from fpga_mgr_dev_release() and ask the > user to free the manager when necessary. > > This makes the usage consistent: the user creates and destroy its own > objects. This is also consistent with our other discussion where we > said, among the other things, that the module that uses the FPGA > manager can the owner of the fpga_manager data structure. You're not the first to complain about this. I think I'll err on the side of consistency and implement your option 2 here. Alan