Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2663900ybh; Mon, 9 Mar 2020 10:23:31 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsjk2G7ys1f9JNZuMr0/QgW0ngrXs9WZzC+zdDLCueoACVHyT0b2CPoBL9imtlbjEEXQXw1 X-Received: by 2002:a9d:7458:: with SMTP id p24mr2050138otk.197.1583774611082; Mon, 09 Mar 2020 10:23:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583774611; cv=none; d=google.com; s=arc-20160816; b=G87iPA6vApD/ecdEV+AfGAHGAgbh+Xpjg/2p8IKXwYb+UBNQ2bexS1tOYpuXWqhc7P PJVKd0OD/BOEbCJJy5fupnT4tEnEouF5KNgSah5B9xFSEd4D6/tGf+f0RF6SV744BDPj zhlbB1pMQqSVwUY+7LzFaB308N1uA0VWYA6i44Cemu6LOVsqae7lOjHgWIoRDso+7Len VYumy7M7sUQ8tewUDG/sAJjOdnDtVeJ4HEi2mNdIst5PKwknfJ4LsV54x4/39b6IeM7O HHpnruSJmcIcRj9tvSgkLk+GXvlWjLv6zzJqsumyq8X1F3CPCykG8nE88X++NEJuA8Xl n/mA== 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 :content-disposition:mime-version:message-id:subject:cc:to:from:date; bh=RpSrK82GO+XpUM86Hc84ckqih+54BcF5pmkDsAsQd94=; b=yti9NYI44WaYAQFI3TCrefFz3LkO3VoptZ9TQgDXy4CrKHDQz+L4JY4opB3/VPmBtS dcZBO5wF/KlWP/sBG00mfNljN1IhLsTjDlvequXtFRmTBzhXQFpyCymJFnv5mWAZjLmN w5z8oWxRT7t0cd7JrrbKN2oHpT50sAJ6ro/FfB4HOnXCKuuTWeaFpoIJTIibxOK+U1AW 1XUpMieCfvjosY9Cgpq/ire+lYPpc4R5O/tRhiMMc1kTiu/IPmDScFIAla6DU43uky5p 2aG0nWmSGsVjCMtLvY3byBo98/pTOkq0qKl0QG8ic/Z8DuQO3jd2B9U8oRX+7zkgHcNW Ff0A== 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1si3969605oix.12.2020.03.09.10.23.18; Mon, 09 Mar 2020 10:23:31 -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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727366AbgCIRWn (ORCPT + 99 others); Mon, 9 Mar 2020 13:22:43 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:34115 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727254AbgCIRWn (ORCPT ); Mon, 9 Mar 2020 13:22:43 -0400 Received: from mail-wr1-f71.google.com ([209.85.221.71]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jBM6z-0000ke-0a for linux-kernel@vger.kernel.org; Mon, 09 Mar 2020 17:22:41 +0000 Received: by mail-wr1-f71.google.com with SMTP id n7so5509964wro.9 for ; Mon, 09 Mar 2020 10:22:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding; bh=RpSrK82GO+XpUM86Hc84ckqih+54BcF5pmkDsAsQd94=; b=tM7EK9CwULG7xZEdqBODzT6JU+ALJp7DCbPpQyQrj60BEJYSWeTCA2JEtSDq9JGgL0 e2u7HR9IOZcwQAQFHBsqTpVBMfWAEjFV33OHD/Gbfv8pZeV9fojBUnridhR1XLFc9ILr 2QCbdBPjBlz0qgZEOXA6EuAC4KQGGJyOylimrLt1Fj2nGslaXYFFg5jkxSV9D7ep5Mxf vqNovIdeqbH6Y7sGUuHYovZ8sUilfLe58NALdcvllY3/fqBKpy42Rxy8rRBGEg21a1Qo KUvNXBO9hHcBiGjI5Qf6D45GVWl9ar9pTaApbdPEpKw31r3pNljnIrZCaB8jTSJ8lTMG o8xQ== X-Gm-Message-State: ANhLgQ1Dg+Qgt+zx3YFUofBWJdCmjmABDf2WaYm3a2EAwcWu+pzGYH63 wHCp1q9JZvufNfZFsHFMcCH7H2BNmSZnGbgZiwgn0xPnSM3yS16qwzU9KG+rR59hoCYmiztsZA3 ZbHc3CfYf0PFHwdhYj7rqngnMioNKwpuy1dBEe1Y1zg== X-Received: by 2002:a05:6000:120e:: with SMTP id e14mr1259387wrx.182.1583774560365; Mon, 09 Mar 2020 10:22:40 -0700 (PDT) X-Received: by 2002:a05:6000:120e:: with SMTP id e14mr1259366wrx.182.1583774560108; Mon, 09 Mar 2020 10:22:40 -0700 (PDT) Received: from localhost (host96-127-dynamic.32-79-r.retail.telecomitalia.it. [79.32.127.96]) by smtp.gmail.com with ESMTPSA id y189sm286063wmb.26.2020.03.09.10.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 10:22:39 -0700 (PDT) Date: Mon, 9 Mar 2020 18:22:38 +0100 From: Andrea Righi To: Richard Cochran , Vladis Dronov Cc: "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] ptp: free ptp clock properly Message-ID: <20200309172238.GJ267906@xps-13> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a bug in ptp_clock_unregister() where pps_unregister_source() can free up resources needed by posix_clock_unregister() to properly destroy a related sysfs device. Fix this by calling pps_unregister_source() in ptp_clock_release(). See also: commit 75718584cb3c ("ptp: free ptp device pin descriptors properly"). BugLink: https://bugs.launchpad.net/bugs/1864754 Fixes: a33121e5487b ("ptp: fix the race between the release of ptp_clock and cdev") Tested-by: Piotr Morgwai KotarbiƄski Signed-off-by: Andrea Righi --- v2: move pps_unregister_source() to ptp_clock_release(), instead of posix_clock_unregister(), that would just introduce a resource leak drivers/ptp/ptp_clock.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index ac1f2bf9e888..468286ef61ad 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -170,6 +170,9 @@ static void ptp_clock_release(struct device *dev) { struct ptp_clock *ptp = container_of(dev, struct ptp_clock, dev); + /* Release the clock's resources. */ + if (ptp->pps_source) + pps_unregister_source(ptp->pps_source); ptp_cleanup_pin_groups(ptp); mutex_destroy(&ptp->tsevq_mux); mutex_destroy(&ptp->pincfg_mux); @@ -298,11 +301,6 @@ int ptp_clock_unregister(struct ptp_clock *ptp) kthread_cancel_delayed_work_sync(&ptp->aux_work); kthread_destroy_worker(ptp->kworker); } - - /* Release the clock's resources. */ - if (ptp->pps_source) - pps_unregister_source(ptp->pps_source); - posix_clock_unregister(&ptp->clock); return 0; -- 2.25.0