From patchwork Thu Sep 1 05:17:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Scott X-Patchwork-Id: 9308337 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DDE4160756 for ; Thu, 1 Sep 2016 05:17:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0092290F5 for ; Thu, 1 Sep 2016 05:17:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4AE429173; Thu, 1 Sep 2016 05:17:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DA43290F5 for ; Thu, 1 Sep 2016 05:17:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751010AbcIAFR2 (ORCPT ); Thu, 1 Sep 2016 01:17:28 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:33237 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750841AbcIAFR1 (ORCPT ); Thu, 1 Sep 2016 01:17:27 -0400 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 08C0786053; Thu, 1 Sep 2016 17:17:24 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1472707044; bh=eHFLc8oogLJHQsuXFJkqJBP31poUHLhHDV11C/I8uvY=; h=From:To:Cc:Subject:Date; b=wBYsvJLTaR4ihJawo4PZ4lTh66iu2IeRB7QYPdXQQrvP58lGbppQ5Y3rbeuC0SkMd mGEU6Iudd5L11AynPYzoGOoFkp9lHdsGAfooPnblaJs1MvUCUVquaHQAzUd88fvLPP eVF8L9NXFJziiipYI3lXcHq4t2y55SGhzPBjg8ow= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 3, 6, 7949) id ; Thu, 01 Sep 2016 17:17:24 +1200 Received: from joshuas-dl.ws.atlnz.lc (joshuas-dl.ws.atlnz.lc [10.33.13.25]) by smtp (Postfix) with ESMTP id 03B1C13EF6C; Thu, 1 Sep 2016 17:17:23 +1200 (NZST) Received: by joshuas-dl.ws.atlnz.lc (Postfix, from userid 1634) id 61B851A05AA; Thu, 1 Sep 2016 17:17:23 +1200 (NZST) From: Joshua Scott To: Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Cc: Joshua Scott , Chris Packham Subject: [PATCH] hwmon: adt7470: Allow faster removal Date: Thu, 1 Sep 2016 17:17:21 +1200 Message-Id: <20160901051721.13806-1-joshua.scott@alliedtelesis.co.nz> X-Mailer: git-send-email 2.9.0 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP adt7470_remove will wait for the update thread to complete before returning. This has a worst-case time of up to the user-configurable auto_update_interval. Break this delay into smaller slices to allow the thread to exit quickly when adt7470_remove is called. Signed-off-by: Joshua Scott --- drivers/hwmon/adt7470.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index 7d185a9..ba97392 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c @@ -268,14 +268,21 @@ static int adt7470_update_thread(void *p) { struct i2c_client *client = p; struct adt7470_data *data = i2c_get_clientdata(client); + unsigned long next_read = jiffies - 1; while (!kthread_should_stop()) { - mutex_lock(&data->lock); - adt7470_read_temperatures(client, data); - mutex_unlock(&data->lock); + + if (time_after_eq(jiffies, next_read)) { + next_read = jiffies + data->auto_update_interval * HZ / 1000; + mutex_lock(&data->lock); + adt7470_read_temperatures(client, data); + mutex_unlock(&data->lock); + } + + msleep_interruptible(1); + if (kthread_should_stop()) break; - msleep_interruptible(data->auto_update_interval); } complete_all(&data->auto_update_stop);