Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp297440imm; Wed, 18 Jul 2018 02:15:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc48yiJcgklcln/dPOYBDGVdfNQedaQxI6af7//fnN82ZWvyN1vyc5o5ak8H/E5ORH4qcOS X-Received: by 2002:a17:902:585:: with SMTP id f5-v6mr5188618plf.7.1531905352786; Wed, 18 Jul 2018 02:15:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531905352; cv=none; d=google.com; s=arc-20160816; b=tUqtWcEWrgVRWMvjA/2LaTB414b2dsnD8XFmKzNuiXlt/IsjyqBq8YagwtN8JpEoqQ Z/eZWedHQaCYSYkmlnBAcRNHRLy6IUo0lTJ6R1npZQvA5w+r4Vc+Z62edCRzigtsRpt8 nc1lfUFS7g0ago/Bh9mSizeKn9bJyMrPo5yOewisosbCGkzA6kuc5iniERIKQKnyG6x8 wROkAdbrq3hkao5e2NwmkK6Tnkz5fkTTm/RmrJ1HgFbVlS8eex8OSpaRlSVJ+kV5VOU4 qOVAfsiwBQpgc3rgHotq/P7yElkgI6yrbgbbSNxo5Re//By4jy27PG27SU70l5e+FAb4 0R9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organisation:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=c0lEzjnUTk86S0WIZV8Thn+E1mUULVMOiuRFNMsOBO4=; b=W/OyGmfiQSbN3qDcUeLvRrYGkph8lyWdjDRsFtafX7m7J08Bw4/mUP3TpOLF6JT6P/ A6gjVH3OIGlufdtU9CHr65cNsYk/cBRDIvInMELx0GwjMlbON7vma3aRQP30ZL5DpIYU RmBGM7dMoPtIVq4VU0J1+16JBSBFWtCWkMKHhBWrUy0yJWPb8+n36bGxEZhaOpxw+G7T zJxl4PAMJz4z0bpVc7di3YQi6tR2SLKn1vaseFVQkuy2Uy7+eAYN/2AdAgPuvaF+PP+5 od0JEWXKhJdct7G02R8FrJEbnVi9w+nclON69usv2VUuUhtReTbfr1DOsS2UHxFmME7r /tIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@verge.net.au header.s=mail header.b=QrFLLWS5; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6-v6si2955881pfy.140.2018.07.18.02.15.37; Wed, 18 Jul 2018 02:15:52 -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; dkim=fail header.i=@verge.net.au header.s=mail header.b=QrFLLWS5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730798AbeGRJvu (ORCPT + 99 others); Wed, 18 Jul 2018 05:51:50 -0400 Received: from kirsty.vergenet.net ([202.4.237.240]:49142 "EHLO kirsty.vergenet.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729619AbeGRJvt (ORCPT ); Wed, 18 Jul 2018 05:51:49 -0400 Received: from reginn.horms.nl (watermunt.horms.nl [80.127.179.77]) by kirsty.vergenet.net (Postfix) with ESMTPA id 5F20D25BE0C; Wed, 18 Jul 2018 19:14:51 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=verge.net.au; s=mail; t=1531905291; bh=EmpRczOHPT+zYUNOn7qLIVM7xx2Y1K39KarvOzDsWgw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QrFLLWS59xLsY3XogPsnFirVDqr0Ec437cR/kOPMG73CtlippJMnxamJfbaafQ1pD jzIoGJ/QCdiylh9Nm44jIh4nNDq5QxKJj74Ysg5YLiEC8VXzkyInQlXSqyWNajZYvw dcAK8kCuyilaIN8KWke7uHOmClzDl6JSKXu8hS/M= Received: by reginn.horms.nl (Postfix, from userid 7100) id 56CB99402E7; Wed, 18 Jul 2018 11:14:49 +0200 (CEST) Date: Wed, 18 Jul 2018 11:14:49 +0200 From: Simon Horman To: Phil Edworthy Cc: Andy Shevchenko , Jarkko Nikula , Geert Uytterhoeven , "linux-i2c@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-renesas-soc@vger.kernel.org" , Mika Westerberg Subject: Re: [PATCH 2/2] i2c: designware: Add support for a bus clock Message-ID: <20180718091448.fw2y7ea6sk2osi3g@verge.net.au> References: <1531731553-22979-1-git-send-email-phil.edworthy@renesas.com> <1531731553-22979-3-git-send-email-phil.edworthy@renesas.com> <20180717120737.bipotpki3yhn6klf@verge.net.au> <40f2729f38bd565a829d60d9cc8f508e33b0dc65.camel@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organisation: Horms Solutions BV User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 17, 2018 at 02:57:27PM +0000, Phil Edworthy wrote: > Hi Andy, > > On 17 July 2018 15:47, Andy Shevchenko wrote: > > On Tue, 2018-07-17 at 14:40 +0000, Phil Edworthy wrote: > > > On 17 July 2018 15:19, Andy Shevchenko wrote: > > > > On Tue, 2018-07-17 at 12:42 +0000, Phil Edworthy wrote: > > > > > > > > > > While your point sounds valid (don't remember how clk_get() is > > > > > > implemented), NULL is also OK to have. > > > > > > > > > > Ok as in there is no bus clock, right? > > > > > So it should be: > > > > > if (!IS_ERR_OR_NULL (dev->busclk)) > > > > > > > > Nope, NULL is no error case for optional clock. > > > > > > I must be missing something here... > > > > See how clk_prepare_enable() is implemented. > Ok, if busclk is NULL the code can safely call clk_prepare_enable() > > > > I agree that NULL for an optional clock is not an error. However, the > > > code above is now: > > > + if (prepare) { > > > + /* Optional bus clock */ > > > > > + if (!IS_ERR_OR_NULL(dev->busclk)) { > > > > Check for NULL is redundant. > > > > > + ret = clk_prepare_enable(dev->busclk); > > > + if (ret) > > > + return ret; > > > + } > > > + > > > return clk_prepare_enable(dev->clk); > > > + } > > > > > > So, if you have a valid busclk, it gets enabled, otherwise it is left > > > alone. > > > So the code as sent in the original email is correct (aside from Geert's > comments about EPROBE_DEFER handling). > > Maybe I need some coffee :\ > Thanks > Phil My point is that errors should be treated as errors. In i2c_dw_prepare_clk() the following appears: if (IS_ERR(dev->clk)) return PTR_ERR(dev->clk); So dev->clk being an error value is treated as an error that is passed up to the caller. But in your patch (and the snippet below) dev->busclk is treated as the optional clock not being present. Even if the error stored nothing to do with the clock not being present - f.e. ENOMEM or as Geert mentioned elsewhere, EPROBE_DEFER. Assuming the absense of the optional clock is indicated by ENOENT, in my view correct code would include something like: ... if (IS_ERR(dev->clk)) return PTR_ERR(dev->clk); if (IS_ERR(dev->buslck) && PTR_ERR(dev->busclk) != -ENOENT) return PTR_ERR(dev->busclk); ...