Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp190683imm; Tue, 14 Aug 2018 16:59:18 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzxoKc5+dPXppT8LMFRfG7H2PArCd9MJsiXUWLk2hbBBVyT49YtrGJ80T/x+0Y0LMelIobO X-Received: by 2002:a17:902:9348:: with SMTP id g8-v6mr22145778plp.302.1534291158164; Tue, 14 Aug 2018 16:59:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534291158; cv=none; d=google.com; s=arc-20160816; b=0Xwkh8Jh4S4LsZXEMoJbfHUmq1guGsYkkVYZYMO6PIJgGiRYvQqieXtfo9gLFeJGxf 0ubS4rUrK8b1Oj5ROhMi/Udv+kpCZ7QPh3PYAe+3wDU+l0xNz/PgnfLo5tlsLjBPupPD EvwwEB4y7vaU6/4mTPo6EoH0JKrB0APt3LDmbvS+lKJg9y3pUHETDgdkuNjF0h6PjJdf qh5ioQPmJMMxAeV7z2E/3a7osEZnAMwN0fY6gIp7IQgGP9gO5+Pzo8mjqCzKZFdUme3h ZjycTU15BQEPlzBU5HdSFaXdDTAbR1LwOlxQ0L/anE2Hkc6Okifw1/Lk1wQVvaBHK8Ek aOnw== 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=TLVUxb1lvVhCAT87qkhJg8AMV4oziJH+ZynyRLPjhC4=; b=auXz+XewdUKDW3RqaPojIeNpUWeZbQO2IRA3cdc+21RpPuT38SOIaA+V2Dg/wjDS/S HL2q3Q5bp9SJVmt8UoyFOgLitu6tlHBUNc+li3FQqU8RYkYmFLc9/ylkS4F24Zaaa64b vOk4SPdse4U4E3v8Ilf5igLS7RPY0UlOUpbaFor7h6nW7oleo9wncs328fi9Vj9G8JoM hWMTG7uppEgsBWzd3oFmZM8XC8FPDTd/V5R3soOEojHsmEVnNuDyi4EFuWPLbcq6lHBV qe0dpGocYsT2N4vdaMgEseISpCa4DkPICUUgfU2uYfDmcx4mlaTUw4Ylfh7hSyDD7Wrp eKoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DgMBMrKe; 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 p131-v6si21794976pgp.343.2018.08.14.16.59.03; Tue, 14 Aug 2018 16:59:18 -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=DgMBMrKe; 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 S1728695AbeHOCrn (ORCPT + 99 others); Tue, 14 Aug 2018 22:47:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:39424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728119AbeHOCrn (ORCPT ); Tue, 14 Aug 2018 22:47:43 -0400 Received: from mail-yw1-f45.google.com (mail-yw1-f45.google.com [209.85.161.45]) (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 84A882170E; Tue, 14 Aug 2018 23:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1534291087; bh=01XDqgzF+7HqaD1pkOZsmZ1HyFXUKtZ/fSsSFb+7MQU=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=DgMBMrKeVFzczuPNlEMywcc4zT5spkYNKQIJC/YGqBj0uI2ybg+DctO/rqC+FhVIQ jLrdhSNVGOoQjulPsYviMppcc88ohQPD+GsQVDmEBPkczqDXK2n1w3bKY3ahVPoBI7 mgObw6q1hsNIad3YWFNqokjXD8UljMcVOQOAPjsE= Received: by mail-yw1-f45.google.com with SMTP id 139-v6so17585019ywg.12; Tue, 14 Aug 2018 16:58:07 -0700 (PDT) X-Gm-Message-State: AOUpUlG5HdMbb2w6muyEsi3IdPw1H2qPg0Hi76d4vuPj/cnNM6XltydD 2v+WFmy5GYFIeTX/2YyGVEMt1Tz3jz0gHPrBrKo= X-Received: by 2002:a25:448b:: with SMTP id r133-v6mr13496670yba.122.1534291086759; Tue, 14 Aug 2018 16:58:06 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:81cc:0:0:0:0:0 with HTTP; Tue, 14 Aug 2018 16:57:26 -0700 (PDT) In-Reply-To: <3092191.aOBZP6MEga@pcbe13614> References: <20180725181514.3501-1-atull@kernel.org> <3092191.aOBZP6MEga@pcbe13614> From: Alan Tull Date: Tue, 14 Aug 2018 18:57:26 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] fpga: Document when fpga_blah_free functions should be used To: Federico Vaga Cc: Moritz Fischer , Florian Fainelli , linux-kernel , linux-fpga@vger.kernel.org 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 Thu, Jul 26, 2018 at 2:26 AM, Federico Vaga wrote: > Hi Alan, > > have you considered the possibility of having something like devm_fpga_[mgr| > bridge|region]_[create|free]() ? Like this, it will be obvious that 'struct > fpga_mgr' will be released automatically without reading any comment (but the > comment is still good), and you use devm_*_free() only to handle error > conditions. Hi Federico, Sorry for the late reply. I was waiting until I had this all implemented. As you've seen, I've posted the devm_fpga_mgr_create implementation [1]. I found I didn't need devm_*_free() for the error conditions, the managed device code handled cleanup nicely without it. Just to be clear, I'm dropping this patch in favor of devm support instead. Thanks again for your suggestions. Alan [1] https://lkml.org/lkml/2018/8/14/954 > > On Wednesday, July 25, 2018 8:15:13 PM CEST Alan Tull wrote: >> Clarify when fpga_(mgr|bridge|region)_free functions should be used. >> The class's dev_release will handle cleanup when the device is released >> so once the mgr/brige/region has been successfully registered, it >> would be a bug to call fpga_(mgr|bridge|region)_free. >> >> Signed-off-by: Alan Tull >> Suggested-by: Florian Fainelli >> Suggested-by: Federico Vaga >> --- >> drivers/fpga/fpga-bridge.c | 10 +++++++++- >> drivers/fpga/fpga-mgr.c | 10 +++++++++- >> drivers/fpga/fpga-region.c | 10 +++++++++- >> 3 files changed, 27 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c >> index 24b8f98..528d2149 100644 >> --- a/drivers/fpga/fpga-bridge.c >> +++ b/drivers/fpga/fpga-bridge.c >> @@ -379,7 +379,11 @@ EXPORT_SYMBOL_GPL(fpga_bridge_create); >> >> /** >> * fpga_bridge_free - free a fpga bridge and its id >> - * @bridge: FPGA bridge struct created by fpga_bridge_create >> + * @bridge: FPGA bridge struct created by fpga_bridge_create() >> + * >> + * Free a FPGA bridge. This function should only be called for >> + * freeing a bridge that has not been registered yet (such as in error >> + * paths in a probe function). >> */ >> void fpga_bridge_free(struct fpga_bridge *bridge) >> { >> @@ -414,6 +418,10 @@ EXPORT_SYMBOL_GPL(fpga_bridge_register); >> /** >> * fpga_bridge_unregister - unregister and free a fpga bridge >> * @bridge: FPGA bridge struct created by fpga_bridge_create >> + * >> + * Unregister the bridge device. The class's dev_release will handle >> + * freeing the bridge struct when the device is released so don't >> + * call fpga_bridge_free() after calling fpga_bridge_unregister(). >> */ >> void fpga_bridge_unregister(struct fpga_bridge *bridge) >> { >> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c >> index a41b07e..9632cbd 100644 >> --- a/drivers/fpga/fpga-mgr.c >> +++ b/drivers/fpga/fpga-mgr.c >> @@ -619,7 +619,11 @@ EXPORT_SYMBOL_GPL(fpga_mgr_create); >> >> /** >> * fpga_mgr_free - deallocate a FPGA manager >> - * @mgr: fpga manager struct created by fpga_mgr_create >> + * @mgr: fpga manager struct created by fpga_mgr_create() >> + * >> + * Free a FPGA manager struct. This function should only be called >> + * for freeing a manager that has not been registered yet (such as in >> + * error paths in a probe function). >> */ >> void fpga_mgr_free(struct fpga_manager *mgr) >> { >> @@ -663,6 +667,10 @@ EXPORT_SYMBOL_GPL(fpga_mgr_register); >> /** >> * fpga_mgr_unregister - unregister and free a FPGA manager >> * @mgr: fpga manager struct >> + * >> + * Unregister the manager device. The class's dev_release will handle >> + * freeing the manager struct when the device is released so don't >> + * call fpga_mgr_free() after calling fpga_mgr_unregister(). >> */ >> void fpga_mgr_unregister(struct fpga_manager *mgr) >> { >> diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c >> index 0d65220..7335fa9 100644 >> --- a/drivers/fpga/fpga-region.c >> +++ b/drivers/fpga/fpga-region.c >> @@ -231,7 +231,11 @@ EXPORT_SYMBOL_GPL(fpga_region_create); >> >> /** >> * fpga_region_free - free a struct fpga_region >> - * @region: FPGA region created by fpga_region_create >> + * @region: FPGA region created by fpga_region_create() >> + * >> + * Free a FPGA region struct. This function should only be called for >> + * freeing a region that has not been registered yet (such as in error >> + * paths in a probe function). >> */ >> void fpga_region_free(struct fpga_region *region) >> { >> @@ -255,6 +259,10 @@ EXPORT_SYMBOL_GPL(fpga_region_register); >> /** >> * fpga_region_unregister - unregister and free a FPGA region >> * @region: FPGA region >> + * >> + * Unregister the region device. The class's dev_release will handle >> + * freeing the region so don't call fpga_region_free() after calling >> + * fpga_region_unregister(). >> */ >> void fpga_region_unregister(struct fpga_region *region) >> { > > > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-fpga" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html