Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1875957lqg; Mon, 4 Mar 2024 06:34:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV96Nwq7M9PHGN/wMtaun0nf8RUbsW2RjcABMae9MzVUbBEHswhDuMdlom8J3QPrATZz1C9l1Sm21yPWwHPCGeEkAglt2SAHGwAqAVC/w== X-Google-Smtp-Source: AGHT+IEvho75oD6sRm0TuqPRFiQs5wuuSrnjqUPvHY6hDU4XbJpPRFESdTUd6PV2IU4VS5I8+dcZ X-Received: by 2002:a05:6a21:9212:b0:1a1:47cd:f84 with SMTP id tl18-20020a056a21921200b001a147cd0f84mr8163588pzb.35.1709562866759; Mon, 04 Mar 2024 06:34:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709562866; cv=pass; d=google.com; s=arc-20160816; b=09+VbelfvlJeofUqN30i0c1sJYYHg2sCoHSv/xmNhY8GoHXCv3Z3YfO7UZcJ2twDKd gzBEn/zG+EMz8bvmhUJQNAOQtHyaMGff/WI9G94OYKQU/4z7C9o9hsNjrtX65+BMNbGh Wj+OYj41U7CoNyT0RxNuCXQ+Nk/SwLPVcMZDxrvFIQzgZ2Q7yPwJw/v1q6Q1DkQ695V6 spmUsgdvJMDIFwH8cXgTZzr3eIxY62LxlywIeuB1sDSD91ZicyII2lcG6hS3iBYspg8k C4XlUNDIH+caFWI1WXmfdc2SezP7hBQLECOEUo+GJzsuZ5cuwiZKt+dBPbyAJTHzZWRF If8A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=VVcCK+YkQiSdvPAjSAPwRLt7JpKB10rUh9LOYhzJwGM=; fh=PLWYQa/SsrRmUoweQCAYBgo2MlXB4aKObXg9xY7m44Y=; b=ZRS+tiax9AU9sEVo2+DSSO4a/8l2sDpLL2JPzGYHMYKMFciov9VAYvoa7DlGIKdSSq wKo0RM+1FBPkOVWGfqhPNf9aKlOaLWJ8k7NvJ+jOimDVASTR3vTcgXt1eZUsZeJmeEDf 0HyTfBaRmk52FEccH6WQ3OT6SSxpgovQUT9ldU0h+9jdw5sDFCP45P4AcOaBmKvUXMsZ aO8cPpR2H4fP0+SBxAx/TM0x65z+Nah/3ilsk1BDpnaRUp3OrtmUX6+oSBoPghW87yCE C2AY5h6D4r5wXxFVpWN4ywq+uL5M04Zq9h0S6LDQamwnul4ljnokkkSpcEifsldKLeuN cnlQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UlFpoy3w; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-90736-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90736-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s16-20020a632150000000b005dc6cbf8440si8465177pgm.99.2024.03.04.06.34.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 06:34:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90736-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UlFpoy3w; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-90736-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90736-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9EC3F2827E6 for ; Mon, 4 Mar 2024 14:32:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D0DDC40BE3; Mon, 4 Mar 2024 14:32:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="UlFpoy3w" Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (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 8A29722630; Mon, 4 Mar 2024 14:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709562768; cv=none; b=agv/mRe4+JX9OgNbxwxMjEw037h8WqF3PQz8AtFJ0YsIAXK2Kk37Hj2Ii94IGnvtl3vXEBy8ZODROPqG/g3auIWAQgnDC8f+A9lcuM2JCE1bnyE3OKdKLg9L7jvp9lHkKhMGITmeno7o4o6KIA5m4Zp62jSbllyJ4pbfa2TH9LA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709562768; c=relaxed/simple; bh=GTxNYf9/QPpJeKyDdvLNK9UeysxfJxAAQUupeLW1ux0=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=SxDpmDEiZELll28xrtxgi1oTgf3nBJoquKeubktizF+Rt0ByMRJC36bBz3YHyLRMZjHZsmVjqB+vmHRELMgSPq0/ypHMUoZFq1ARutqmae+VO7xz95OdWta6ePwo3DWqZYipc+TcT98TPBNqMTzKlUV7ef6BzUGoxSPO/5S/4Cc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=UlFpoy3w; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id CFD5FE0016; Mon, 4 Mar 2024 14:32:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1709562759; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VVcCK+YkQiSdvPAjSAPwRLt7JpKB10rUh9LOYhzJwGM=; b=UlFpoy3wrHro67QQBJ0DptvXOr4Cqkfs1JFHZjHquMpwfsgqOWNanaS78AQYrF9yxr6PXj 9TpZZSsXQxDYVwQOyuta/S9JRhVfqZS+52iaQkzZ8LF3DByo60Fgk7BkVMVM7UBw4gk3kx UgmdtzavFb9uDZmyYbSxz6M2i4CEeWe2KpmTL0qRUV8PhtiLEI9JzQS5S1ory1ZPRDs9D9 uDjcKKpSZ+20wWrm5gMYzwfbqm6ROWR9eFRvCdLuCTH0sNzPftgyRkwABBtcaeQkXHPuic jHFsqlcnpDG3KELTx5kgf9eeRN+Xvg3h2SsDW4pjudTqcLNy+Cf3F/MesMR7zg== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 04 Mar 2024 15:32:38 +0100 Message-Id: Subject: Re: [SPAM] [PATCH v2 06/11] i2c: nomadik: support short xfer timeouts using waitqueue & hrtimer Cc: "Linus Walleij" , "Rob Herring" , "Krzysztof Kozlowski" , "Conor Dooley" , "Thomas Bogendoerfer" , , , , , , "Gregory Clement" , "Vladimir Kondratiev" , "Thomas Petazzoni" , "Tawfik Bayouk" To: "Andi Shyti" From: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: aerc 0.15.2 References: <20240229-mbly-i2c-v2-0-b32ed18c098c@bootlin.com> <20240229-mbly-i2c-v2-6-b32ed18c098c@bootlin.com> In-Reply-To: X-GND-Sasl: theo.lebrun@bootlin.com Hello, On Mon Mar 4, 2024 at 2:54 PM CET, Andi Shyti wrote: > Hi Theo, > > ... > > > +static bool nmk_i2c_wait_xfer_done(struct nmk_i2c_dev *priv) > > +{ > > + if (priv->timeout_usecs < jiffies_to_usecs(1)) { > > + unsigned long timeout_usecs =3D priv->timeout_usecs; > > + ktime_t timeout =3D ktime_set(0, timeout_usecs * NSEC_PER_USEC); > > + > > + wait_event_hrtimeout(priv->xfer_wq, priv->xfer_done, timeout); > > + } else { > > + unsigned long timeout =3D 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 =3D priv->timeout_usecs; ktime_t timeout =3D 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. > Reviewed-by: Andi Shyti Thanks for your review Andi! -- Th=C3=A9o Lebrun, Bootlin Embedded Linux and Kernel engineering https://bootlin.com