Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1900351lqg; Mon, 4 Mar 2024 07:11:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWqci6YZ2VeHTIfXQZaGo6bHwIQ0ksVcIRr+MswTUjaiodKOcyoJX02ZnY6tUvf1oVsrcE8zMou2klB82qEpDg9ePFpZzeDYs1hqX8JVg== X-Google-Smtp-Source: AGHT+IFE7Aq4dd+FRcNQIo6NAjkESvuYgOdJeHRrnBoDcvhQnzvzWdPMAadONhgNeKLqOz1Rc0Ln X-Received: by 2002:a05:620a:5e0a:b0:788:2769:a51e with SMTP id xz10-20020a05620a5e0a00b007882769a51emr2968455qkn.54.1709565084576; Mon, 04 Mar 2024 07:11:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709565084; cv=pass; d=google.com; s=arc-20160816; b=oJMLpMiA7uEE1MSN3QFVdvKryjMlllDZpffLwclmezJZjZUngnIetsB6W8KX9/gBqc i6LPwzvCCU94tcji4wADkvFcwJJqwyerOYvMOLBpB/jqmXaILMwJeQmdV/1GS5vMGvWh U5c7PWzpuhfvBjxXXoIimwT1Q4z3dVk5GLU7b0AYXI6Al2slHCDOshFFLq917yuqdYUB jPVL3fB4UcEzCEB63cai2rA7Daz0TtNQGrN7suNZck8WWXe49nl4HcF7ZCkmgQho7nPZ O4Vq1xe/SyAXfPy+QbC/IM5lNghFmk8hCcc9nfud90DUuTVh0kwlXe5CFABlAzYjTpH7 t3fQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MA1c+R97eljObfkhODIfSk4OFWEjcptUiNg9uJF1fL4=; fh=LKv7/ECdWOvQ8HRyO3fxFfve947qkEq8wuprEhmK6uY=; b=K9yZhYvZ0pPiL6+QUcs/VjIWo08XWESAejeuYqKM7oUXgx2gtN9dyzE9mbw9XvNabC HWnqmaNzIeFSzOkUFR49BD+MBWjCF5/dA4kPnpb4yb+S7+bWC/3WCRBROgGqq2D7HOks RZCF45Hvdv+w8EzHRdSJRlv1vQ5eiSZK2NNLyqvaz86aGY4UjaqGuxD3ezN2MfSzbMGN kbDZ71tBVNdQnjPGzL3RpcttIuPt4Qxucu8HUGWQAs+wYRPf8YGARHyiJ0uJ0a4nzMEs bf80/fH3Nq634BR3k41l+AEJuBQwSvtS96iyO/p5ZYBTzKBwrzo5qRRvIoKulXw5sxPJ Wxbg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NcJBfY3t; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90778-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ow27-20020a05620a821b00b00787c6efd700si9711654qkn.340.2024.03.04.07.11.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 07:11:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NcJBfY3t; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90778-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2B6E11C216C0 for ; Mon, 4 Mar 2024 15:11:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A930482EB; Mon, 4 Mar 2024 15:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NcJBfY3t" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 343614653A; Mon, 4 Mar 2024 15:09:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709564983; cv=none; b=iF1SA613CXY4B6o/HXSwFgvHNcD1EYdSltg2QzPF0Qf+l61fYGvP4T2wF/WZEAo4ntKmUKVkUTqWbnK1iu1WWmc/4LCO/H23d3tSdhzZHHWCbZqI9I5AMNnUeHDbOAKABXtSMbTuKM6bGkKIu2wCrcdt1dHsAHakfTQuQR/SiqE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709564983; c=relaxed/simple; bh=0EN/djUllp20WYcpsZJ+YqgTYOv5D/8q+MIeYGrZwYs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=T6tat9dOhlSbDaN8zi07nUWJJXel39CrStkuJP78Lw13xOlZ3KvYQJLXnbaFpmcyCLGNpgKrxjHC4rF2LRlBvjjvMSqOWueo1nLbSiMOF6PK+YEiN/1ZDG62M6TRridDz+I2OlwGGA/WMKv/hJdAN0ruMcIkIQ9WmGZbz9MggVw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NcJBfY3t; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 101C1C43399; Mon, 4 Mar 2024 15:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709564983; bh=0EN/djUllp20WYcpsZJ+YqgTYOv5D/8q+MIeYGrZwYs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NcJBfY3tWVDpuLt/lYCRgDIKDTl7ZAxziWE8a75pn2ypL9ZwdKNKqAK55sRqNjNDx H+0HetMxYYbBKxO/vdb8Ve8331ccpLJXo2tWedX+hxJxqTtSBxVKlsTS21Ui2Ibnd0 jwR2fECfOjr1uh4gkXYbNWW1p0tVRlgDcZKqLHcZTsgYmGcyMarFY98PGSNP2XWSvh eRDOYtqTcVp2ypAhC/ZoeL2EG+jx4JrbeLVjVXnaBTRGR11z2YxbsOwVeNa10HP7UZ 1k7SWDzWnHyBFtW8BFVvMO/cVpTRh/+ZODJNQc6ox52eo8CYpM9Z97kbrEGwMLPX3s wfSFdiQrjZzLA== Date: Mon, 4 Mar 2024 16:09:38 +0100 From: Andi Shyti To: =?utf-8?B?VGjDqW8=?= Lebrun Cc: Linus Walleij , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Thomas Bogendoerfer , linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Gregory Clement , Vladimir Kondratiev , Thomas Petazzoni , Tawfik Bayouk , Andi Shyti Subject: Re: Re: [PATCH v2 06/11] i2c: nomadik: support short xfer timeouts using waitqueue & hrtimer Message-ID: References: <20240229-mbly-i2c-v2-0-b32ed18c098c@bootlin.com> <20240229-mbly-i2c-v2-6-b32ed18c098c@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Hi Theo, On Mon, Mar 04, 2024 at 03:32:38PM +0100, Th?o Lebrun wrote: > On Mon Mar 4, 2024 at 2:54 PM CET, Andi Shyti wrote: > > > +static bool nmk_i2c_wait_xfer_done(struct nmk_i2c_dev *priv) > > > +{ > > > + if (priv->timeout_usecs < jiffies_to_usecs(1)) { > > > + unsigned long timeout_usecs = priv->timeout_usecs; > > > + ktime_t timeout = ktime_set(0, timeout_usecs * NSEC_PER_USEC); > > > + > > > + wait_event_hrtimeout(priv->xfer_wq, priv->xfer_done, timeout); > > > + } else { > > > + unsigned long timeout = usecs_to_jiffies(priv->timeout_usecs); > > > + > > > + wait_event_timeout(priv->xfer_wq, priv->xfer_done, timeout); > > > + } > > > + > > > + return priv->xfer_done; > > > > You could eventually write this as > > > > static bool nmk_i2c_wait_xfer_done(struct nmk_i2c_dev *priv) > > { > > if (priv->timeout_usecs < jiffies_to_usecs(1)) { > > ... > > > > return !wait_event_hrtimeout(...); > > } > > > > ... > > return wait_event_timeout(...); > > } > > > > It looks a bit cleaner to me... your choice. > > The full block would become: > > static bool nmk_i2c_wait_xfer_done(struct nmk_i2c_dev *priv) > { > if (priv->timeout_usecs < jiffies_to_usecs(1)) { > unsigned long timeout_usecs = priv->timeout_usecs; > ktime_t timeout = ktime_set(0, timeout_usecs * NSEC_PER_USEC); > > return !wait_event_hrtimeout(priv->xfer_wq, priv->xfer_done, > timeout); > } > > return wait_event_timeout(priv->xfer_wq, priv->xfer_done, > usecs_to_jiffies(priv->timeout_usecs)); > } > > Three things: > > - Deindenting the jiffy timeout case means no variable declaration > after the if-block. This is fine from my point-of-view. > > - It means we depend on the half-mess that are return values from > wait_event_*timeout() macros. I wanted to avoid that because it > looks like an error when you read the above code and see one is > negated while the other is not. > > - Also, I'm not confident in casting either return value to bool; what > happens if either macro returns an error? This is a theoretical case > that shouldn't happen, but behavior might change at some point or > bugs could occur. We know priv->xfer_done will give us the right > answer. > > My preference still goes to the original version, but I'm happy we are > having a discussion about this code block. sure... it's not a binding comment. Andi