From patchwork Mon Jun 14 17:09:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moritz Fischer X-Patchwork-Id: 12319489 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=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 DA16FC2B9F4 for ; Mon, 14 Jun 2021 17:09:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C16FC61185 for ; Mon, 14 Jun 2021 17:09:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235485AbhFNRL4 (ORCPT ); Mon, 14 Jun 2021 13:11:56 -0400 Received: from mail-pf1-f176.google.com ([209.85.210.176]:36774 "EHLO mail-pf1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235403AbhFNRLz (ORCPT ); Mon, 14 Jun 2021 13:11:55 -0400 Received: by mail-pf1-f176.google.com with SMTP id c12so11023528pfl.3 for ; Mon, 14 Jun 2021 10:09:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=64IvQlrXeou9jXkno2E2GgEDTZxDLn+r8yPnV7jM6oo=; b=PTFh+wR3BfMUsUFYBkD28ry8bASJiIgV2+eSB5rM44x5OHB7/sjeg3aE4/QZv7kmlg vc5Y3a7HBVwKyn0INNDnED1WanoZ61Lhv9hpviejR0dS+f7uWAkHCILOj6dWpCsYJCzP JFxXFKAh88ksDkPyc4hHdy2Pv6Yvi3Wnw7zT0RciD2hAhdLVCv5i43GeT/W3x9X35DyE xuDEzi7h/w1vCJwQQKENhlFyh1/5MPWZsUontJSSHpms8Jnmm8nNSxSMI+qFr18u3zBU xtseqdSiCmdrdojGKPiJL+hIHF8b1t433elvKMI+ySCAKVVuqmgCUk1EbHdjMzXh36Fv vE+w== X-Gm-Message-State: AOAM533dqhSRwT5c/1K1SLQ9uxgNb/v1NXhiQvrs24hQb7ipWx5QuaBd PTFzWSfjV/YOTPwFdmx42BE= X-Google-Smtp-Source: ABdhPJx5kOEjSsaSYR/Db6aGJrE6a9pEL2diVwV4qJ/d7Cqzg+CY5I86v7QtB/7EDnPBHpnKlDlddw== X-Received: by 2002:a65:624e:: with SMTP id q14mr17720484pgv.103.1623690575797; Mon, 14 Jun 2021 10:09:35 -0700 (PDT) Received: from localhost ([2601:647:5b00:1161:a4cc:eef9:fbc0:2781]) by smtp.gmail.com with ESMTPSA id 20sm12842816pfi.170.2021.06.14.10.09.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 10:09:35 -0700 (PDT) From: Moritz Fischer To: gregkh@linuxfoundation.org Cc: linux-fpga@vger.kernel.org, Moritz Fischer , Russ Weight , Xu Yilun Subject: [PATCH 8/8] fpga: region: Use standard dev_release for class driver Date: Mon, 14 Jun 2021 10:09:09 -0700 Message-Id: <20210614170909.232415-9-mdf@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210614170909.232415-1-mdf@kernel.org> References: <20210614170909.232415-1-mdf@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org From: Russ Weight The FPGA region class driver data structure is being treated as a managed resource instead of using standard dev_release call-back to release the class data structure. This change populates the class.dev_release function and changes the fpga_region_free() function to call put_device(). It also changes fpga_region_unregister() to call device_del() instead of device_unregister(). Signed-off-by: Russ Weight Reviewed-by: Xu Yilun Signed-off-by: Moritz Fischer --- drivers/fpga/fpga-region.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c index 4d60d643cada..bdc15fab60c0 100644 --- a/drivers/fpga/fpga-region.c +++ b/drivers/fpga/fpga-region.c @@ -204,8 +204,10 @@ struct fpga_region return NULL; id = ida_simple_get(&fpga_region_ida, 0, 0, GFP_KERNEL); - if (id < 0) - goto err_free; + if (id < 0) { + kfree(region); + return NULL; + } region->mgr = mgr; region->get_bridges = get_bridges; @@ -219,17 +221,12 @@ struct fpga_region region->dev.id = id; ret = dev_set_name(®ion->dev, "region%d", id); - if (ret) - goto err_remove; + if (ret) { + put_device(®ion->dev); + return NULL; + } return region; - -err_remove: - ida_simple_remove(&fpga_region_ida, id); -err_free: - kfree(region); - - return NULL; } EXPORT_SYMBOL_GPL(fpga_region_create); @@ -239,8 +236,7 @@ EXPORT_SYMBOL_GPL(fpga_region_create); */ void fpga_region_free(struct fpga_region *region) { - ida_simple_remove(&fpga_region_ida, region->dev.id); - kfree(region); + put_device(®ion->dev); } EXPORT_SYMBOL_GPL(fpga_region_free); @@ -310,12 +306,16 @@ EXPORT_SYMBOL_GPL(fpga_region_register); */ void fpga_region_unregister(struct fpga_region *region) { - device_unregister(®ion->dev); + device_del(®ion->dev); } EXPORT_SYMBOL_GPL(fpga_region_unregister); static void fpga_region_dev_release(struct device *dev) { + struct fpga_region *region = to_fpga_region(dev); + + ida_simple_remove(&fpga_region_ida, region->dev.id); + kfree(region); } /**