Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp392209imm; Wed, 18 Jul 2018 04:08:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcxUbFJcd62AJ+uuxsab9pIodGebuamCbPbH2k4pzv5yyr+LVVsLszsGNQI/giGTdm4PpG2 X-Received: by 2002:a63:9619:: with SMTP id c25-v6mr5300692pge.75.1531912094931; Wed, 18 Jul 2018 04:08:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531912094; cv=none; d=google.com; s=arc-20160816; b=KTYOf/4kY7JZCpPUjF5j+g8AOEo1C5+JROMtkzDIn8p1lrtma+EjSO4QiTQDR5Yo9l 9hwdovBuzdJURbjivpxUCBAZYbG6s5nyM4KEjypqBv3pnsv/bf4WlGPhqw5ZYad48Yg0 M012sL3vkJa7z5frXHpxEpc4oAODFmG5YOdaDRSViHHjn4Tb8oCpMX6vGaCjsm8jtxKW 2dwkwTgYFIklc86/sWgdnZrVCtf/Y0EGC6i17hTJBkXQzlZ2zE0K1TrWdCVxcweTirnj 98AMjzGFYqQSrKMRTBCwoi/B1wNdawDLTJCXBFiWpJzXQaOKzi3MkoYyI3HKvflJxXhy W/Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:arc-authentication-results; bh=ILOmiLYMi6v4SrcKSbcNHNZnPsAHz2xcc9s0MFAcU0A=; b=LrrRnTMJd/qMiP4R66kbFOp7ORAMwqIjuOijWKM9giI9ndzPLu+H8j8DZvLr3D5V40 nc5HvQDpJ4XBMtGuzeRuu5ifT3Ju/R4G+oEfZzJDiAl0qYXU45p8BjAHM54jD5TZ5VU1 eK9+Xe9i/EhQFI9BZimdtpfVM2nEFMfnKY6YmA+KmA+74Qtkj4YC4RZJTGB6u0NHh6aA G4VWwT3GvuKZekiiKUNQjPdOb/B4LZYkYXgVHA52dnWbgydl4GivTPPPgRRNWuwe+Vvj aftUg5XWrZPmUWgk6aIKJebzdW5/GEc5H55Kdliyh6ZMzm8LhpVIEC3JVMlabJT6pn3/ bD5A== ARC-Authentication-Results: i=1; mx.google.com; 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 b2-v6si2917781pff.192.2018.07.18.04.07.59; Wed, 18 Jul 2018 04:08:14 -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; 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 S1730329AbeGRLns (ORCPT + 99 others); Wed, 18 Jul 2018 07:43:48 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:42651 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728565AbeGRLns (ORCPT ); Wed, 18 Jul 2018 07:43:48 -0400 Received: by mail-vk0-f68.google.com with SMTP id t4-v6so2253899vke.9; Wed, 18 Jul 2018 04:06:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ILOmiLYMi6v4SrcKSbcNHNZnPsAHz2xcc9s0MFAcU0A=; b=U4o7jkS54CmRENm0H63HjP3ti5WHSMfhivEe2DEXd2y5lsf9L0rNNnJSOwGK1Tc/SU Y5SVp8Cf+TrEhamqKhI4qR25dfVpNMHQkkD+JSSzF1yMe85ZqIOmw6uS085T1Ex0RnZq b0RhkIFVJO77Uu5wuhKIVdqTmWKm//D6rJHh9tO4kCH+o1Lyibr8tsiOA3M5dhH6iLbj UY1/1C8RKG45b96BrD9ZvnJwGV7U5ElCehH7r7+6J9p/VbhZzcg0RvqQpAFj4JBy5cDL xdcqsBtz02MF7h0cnigbcLFKof2AfmLSaBwvtco62uZ/kZVI4wBjUI63/vs/hthkmkEV FuoQ== X-Gm-Message-State: AOUpUlF2AH9WMpV3UMbp5G5f34x0Qo7i3zNWexI06nTgsR1Esy9x59ZI hW0rxCV45b2JzFroeC8O4YwNy5mhsnXgNHItI0FqHg== X-Received: by 2002:a1f:20d4:: with SMTP id g203-v6mr3090857vkg.176.1531911984258; Wed, 18 Jul 2018 04:06:24 -0700 (PDT) MIME-Version: 1.0 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> <20180718091448.fw2y7ea6sk2osi3g@verge.net.au> In-Reply-To: <20180718091448.fw2y7ea6sk2osi3g@verge.net.au> From: Geert Uytterhoeven Date: Wed, 18 Jul 2018 13:06:12 +0200 Message-ID: Subject: Re: [PATCH 2/2] i2c: designware: Add support for a bus clock To: Simon Horman Cc: Phil Edworthy , Andy Shevchenko , Jarkko Nikula , Linux I2C , Linux Kernel Mailing List , Linux-Renesas , Mika Westerberg Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 18, 2018 at 11:14 AM Simon Horman wrote: > On Tue, Jul 17, 2018 at 02:57:27PM +0000, Phil Edworthy wrote: > > 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); > > ... As this is a commonly-used construct, perhaps it would be good to introduce clk_get_optional() (cfr. gpiod_get_optional()) and devm_clk_get_optional(), which would return NULL instead of -ENOENT? Then it becomes a simple check for IS_ERR() in the driver. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds