Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp957331ybm; Wed, 27 May 2020 12:09:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5Z980bDtoIs+I0LGv47jNaXUW18OA2YDISO//GCBkp/YgZ80CUPtQHIlQisGlWcLDiCyL X-Received: by 2002:a17:906:f112:: with SMTP id gv18mr7244666ejb.142.1590606573910; Wed, 27 May 2020 12:09:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590606573; cv=none; d=google.com; s=arc-20160816; b=BNjOmTNt9QsV1iIZitIc0fHLVjRFs2CRcr8ghwSWSAzw/Azq/1v453VFBUh4xpg5vY NIW4a59jYeFr5iyX4jnDtZkAEZwXIdFYTL1NMp+Lqf2Hv7GjA66kw/ybNjsNJ+dnV6BW N4K0iGBEA6TR7pA8lEh11DsypIKvQ20KOv6Oz1OBMsFvgrY3QK+3ddYHBx4y9uRCa4Nu RVBXP3YSkBQ46bDp+e9fNW+7K3cb/FS3oxn/6o6KkjP4heH6c8OgZpZslFJl4VgQ2/Cb DR1t6Q3upP4PhusZ29j8huFa75Bs+Sz7mq/ROqzAujEoLvz5SsqcV2+mjAcfDnsW0YVK 80nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=WgRQyQwNaX2Goqkqxz56C3W/9OHLQN2Fvi2hNnz9VHI=; b=ShSOWuXvvLM3hofpTQPg6hmf9uhu5MF4dnADBmfr6oWK8lFzX7h7VVa6dTNYuCYYjj QqZFy2vpyFScxu+Dz0boa7mCUcDYA3asPDOQ+4607uBbaKSnakwxDiJ/jkr9+0YA948D aQdDst1gfm1xUSkgl1eKnZ6IlDdUHeDv47hNGBn6+oGWwPK0NxE42gWLfV+R6l8QQLLE x2MUp7gBolMClYio02aQAePaHSk/hOFP/hw+nYI/8LyZvtkbmHM5tNBj1o3O0AlQKWUI EOrV8PTTss3/fWrqBFUal0T6x0GSaa4TxMH7/6+sA07LuJ92BeNKaAKe9ok8S03ncvRB tczA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=WXTLKlT4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j14si2360445ejy.206.2020.05.27.12.09.10; Wed, 27 May 2020 12:09:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=WXTLKlT4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730832AbgE0QWI (ORCPT + 98 others); Wed, 27 May 2020 12:22:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729884AbgE0QWG (ORCPT ); Wed, 27 May 2020 12:22:06 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C241AC05BD1E; Wed, 27 May 2020 09:22:05 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id x13so11996458pfn.11; Wed, 27 May 2020 09:22:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=WgRQyQwNaX2Goqkqxz56C3W/9OHLQN2Fvi2hNnz9VHI=; b=WXTLKlT4DSOWS/QRKEwgBx60e9PUQpxizuyNumqo9hlcg+j3aIK5IypbY3wiuPvCrP lHSWKRJT3401/pzlyYSaYaWCaNtIx0Oe3uFVjduyC4rhRalJ1Jiumd2PBBbu1VQGektE fvMdxe7j4VGD12lK9gQNKu+Fu3icGdPQK6zIEbNymJbzp/UQYe3rAKDZb2X0FLY+b0ps MptKaUwzRzIk/pooiucYQXy2bnpWEGt00Vb4HJx6bVoyHeNVURmUS8+6PXwxdWGCXCQ5 L+sU2jjXvrMGONnXjeYig+bYNLnWUeicbCGqU61nnx3nhFJky0eAyWRlO98J6PcSZ9Xg wRaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=WgRQyQwNaX2Goqkqxz56C3W/9OHLQN2Fvi2hNnz9VHI=; b=n9+56mDD4ff55NyYiicO/4l5N6gqvYlGw+KoApEy1TjNucg62X8X1k3ChJIyGXQ2gW 4HyTNfdfGWxFrBkzk2LX9sepVzm/ep6QZSsallUaWuULd/ykFfIougp6Clw24PwbX6LH /xMwJisyzbnliDUlKn88ZytbwtklNHwYtvqEILHK6thvF7h9Foqk1iUJlvdnzhyH+7Vv m/eKmBzliY7yWHmptiyS6z82wjj5tkzg/+vvN2RRmqDgx5jdISE/EwHEnGb78oXh3MCb 6Z3BqSYNQM3pa6EveH5i8YG5vYEMx/b3YTPJln9M5+ibW3YJLE9v9zObe1Sws1QWOe9X BJqA== X-Gm-Message-State: AOAM532RZMk4MoNGf6ox7Bwp14/ZNGTp74mb1g3ZzSC24eZad4jt103O PwIoG9KV8SekzpRDDpnQWsGYXEgR X-Received: by 2002:a62:1d89:: with SMTP id d131mr4679473pfd.294.1590596525275; Wed, 27 May 2020 09:22:05 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id w26sm2469857pfj.20.2020.05.27.09.22.04 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 May 2020 09:22:04 -0700 (PDT) Date: Wed, 27 May 2020 09:22:03 -0700 From: Guenter Roeck To: Arnd Bergmann Cc: Henrik Rydberg , Jean Delvare , Richard Fontana , Dmitry Torokhov , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] hwmon: applesmc: avoid overlong udelay() Message-ID: <20200527162203.GA149714@roeck-us.net> References: <20200527135207.1118624-1-arnd@arndb.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200527135207.1118624-1-arnd@arndb.de> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 27, 2020 at 03:51:57PM +0200, Arnd Bergmann wrote: > Building this driver with "clang -O3" produces a link error > after the compiler partially unrolls the loop and 256ms > becomes a compile-time constant that triggers the check > in udelay(): > > ld.lld: error: undefined symbol: __bad_udelay > >>> referenced by applesmc.c > >>> hwmon/applesmc.o:(read_smc) in archive drivers/built-in.a > > I can see no reason against using a sleeping function here, > as no part of the driver runs in atomic context, so instead use > usleep_range() with a wide range and use jiffies for the > end condition. > Me not either. > Signed-off-by: Arnd Bergmann Applied. Thanks, Guenter > --- > drivers/hwmon/applesmc.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c > index ec93b8d673f5..316618409315 100644 > --- a/drivers/hwmon/applesmc.c > +++ b/drivers/hwmon/applesmc.c > @@ -156,14 +156,19 @@ static struct workqueue_struct *applesmc_led_wq; > */ > static int wait_read(void) > { > + unsigned long end = jiffies + (APPLESMC_MAX_WAIT * HZ) / USEC_PER_SEC; > u8 status; > int us; > + > for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) { > - udelay(us); > + usleep_range(us, us * 16); > status = inb(APPLESMC_CMD_PORT); > /* read: wait for smc to settle */ > if (status & 0x01) > return 0; > + /* timeout: give up */ > + if (time_after(jiffies, end)) > + break; > } > > pr_warn("wait_read() fail: 0x%02x\n", status); > @@ -178,10 +183,11 @@ static int send_byte(u8 cmd, u16 port) > { > u8 status; > int us; > + unsigned long end = jiffies + (APPLESMC_MAX_WAIT * HZ) / USEC_PER_SEC; > > outb(cmd, port); > for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) { > - udelay(us); > + usleep_range(us, us * 16); > status = inb(APPLESMC_CMD_PORT); > /* write: wait for smc to settle */ > if (status & 0x02) > @@ -190,7 +196,7 @@ static int send_byte(u8 cmd, u16 port) > if (status & 0x04) > return 0; > /* timeout: give up */ > - if (us << 1 == APPLESMC_MAX_WAIT) > + if (time_after(jiffies, end)) > break; > /* busy: long wait and resend */ > udelay(APPLESMC_RETRY_WAIT);