Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8492510ybi; Thu, 6 Jun 2019 13:19:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwo64EFlCeBfRqleSZj7frZGJRtl1V9OWsIBrLzPpAa5srDGVmiQrmjY3Vc9oqbNSAFw8b7 X-Received: by 2002:a17:902:324:: with SMTP id 33mr52173694pld.284.1559852365154; Thu, 06 Jun 2019 13:19:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559852365; cv=none; d=google.com; s=arc-20160816; b=xl00rj1z9rkpL4eocHcXA3grliJdc8h/5XtNT4I2+YdgaRWbxMtQFtqkXRGobdaXHZ A1nAQ8LFClwpMv0+eJxWZTzjRfFVmDuI3+7InbSNgWrO7pYvxYx0UhPGn0h8Lgh39jUv P4UjSud7egtwFeQlmVmC7+AiG7mMfTxEza0gg/nvOH1tKskX3iKU+YabN65iYiOM4qMC CMs8BkJSQ/icxehjDC2yyMNeAZSnk0lzusVkCtwaaYKIZg/bJpBtN36p4B72cGWj8Svc lzoqsJytGAgOimKfPRxIwWsC2By+g4QLRBEtbLDsdRwys+mt0fvX8j9E+nzGfhqRmUuc E1VQ== 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:dkim-signature; bh=KHvZ08UQ6F9DrHSAJkdM4lRvAaL9fp+PzcKQDvAi3QA=; b=AUt9TPf44GMnna4/BiV9JOgULuAZ8gyD84AOXmrpRyGR6sXV6VJjqG54MBVDln3qgj lqenXSxSR8Bc9+ojm93eYTKGVvx1IWzV0JGxpT6nzCACrjkTls2naFBW/BC/yY2H/WwP VpRGgKQEw2/ZeDWtXgJeo58PSzySK7AIWPXle/lZ8BpHZbi3N33jPeJYqAk/EmvKf4Mh PkccdMFlIvvw+M0do6oVKZD5D9MsYXOeeAguua/MgHFHPMmol0peJZXrc+YR5bpAwnT5 3oujuK5gN6f5h1p+e/In/ms3PLIMk6A7Zu4tRUYAFEj8ddbcEz8xFeEaJyHf6ZJT2slB zNMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jbDvBSQK; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si2633854pfi.249.2019.06.06.13.19.09; Thu, 06 Jun 2019 13:19:25 -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=pass header.i=@gmail.com header.s=20161025 header.b=jbDvBSQK; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727612AbfFFTwJ (ORCPT + 99 others); Thu, 6 Jun 2019 15:52:09 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:33547 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727047AbfFFTwI (ORCPT ); Thu, 6 Jun 2019 15:52:08 -0400 Received: by mail-io1-f67.google.com with SMTP id u13so1208756iop.0 for ; Thu, 06 Jun 2019 12:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KHvZ08UQ6F9DrHSAJkdM4lRvAaL9fp+PzcKQDvAi3QA=; b=jbDvBSQKpvmcMfisYPWINLkIs3i3NZs3RpdPSdnRUOHZnK1IOgnssVmxivPMMSoK4e nv/niDA3x/sHbTqqGxpF7OBCH1o4MvD1RBWwK2KQoN7/h2miH0lAtmdrkm47ZBrYI13w zt7vPo7wvgZLRvh1Gbnb6uHqUNOp1C1yUqwme7OSii8ttZ7QiWEESYK8uRtN5RF5QTrU BN693xbH+tersd1T+gYqV8Tvly0puO4lUKcMojAn4ieh8PAhmYlk01sk9Pgx3tzF/Pg/ zmisvsJvs5pc9GzSL93Q4yWuXqYhyOkJmKKu74bQDnGI01kFwj9PQ7nwZ6XjK7Z6nb2Q +0wA== 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=KHvZ08UQ6F9DrHSAJkdM4lRvAaL9fp+PzcKQDvAi3QA=; b=oW8LhAirENvnZdApuCEaawnBZYrxd6O7EPcNjjqBzg8Ep1HhSStBCLvt70CskShc0I bmsEzH52/U7S7VUdCZGMkGQqFZ4Id0zjs9k/peIV8zbrsHAayK93uEC2W1Or0GUCQozI tfwJqXUXTFPxZt7BvKJ6mJWIjPJeJLNcTsaahWdTk6dNwnAkwj0OUHXUSqgfUHW9+gze bfoHjk6IIdJrHL6Gp1M+7AzS4sktN1VJcAueopi3y3YgYKEO1BJDjYbiR+4Xqs0l2dsE 9w/jqMMD+LGB72Lr/CmU3/AQjcO53x+d++Xle4+SoQpQyF65g1p8lXHeRE+LHsvrcemN wqNw== X-Gm-Message-State: APjAAAV4yC5PjQymLlxy8NAcAIs1xG4C6p+6NxYXdpbTBC03VKO+bIE4 RhBZEQBAsfRtqr0FGK4wtKLDUlFSoVAB+mJu5Fk= X-Received: by 2002:a6b:f607:: with SMTP id n7mr7342606ioh.263.1559850727465; Thu, 06 Jun 2019 12:52:07 -0700 (PDT) MIME-Version: 1.0 References: <20190605070507.11417-1-andrew.smirnov@gmail.com> <20190605070507.11417-6-andrew.smirnov@gmail.com> <9f847830-7bc6-c377-5cd7-b3cff783cbb3@samsung.com> In-Reply-To: <9f847830-7bc6-c377-5cd7-b3cff783cbb3@samsung.com> From: Andrey Smirnov Date: Thu, 6 Jun 2019 12:51:56 -0700 Message-ID: Subject: Re: [PATCH v3 05/15] drm/bridge: tc358767: Drop custom tc_write()/tc_read() accessors To: Andrzej Hajda Cc: dri-devel@lists.freedesktop.org, Laurent Pinchart , Tomi Valkeinen , Andrey Gusakov , Philipp Zabel , Cory Tusar , Chris Healy , Lucas Stach , linux-kernel 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 Thu, Jun 6, 2019 at 3:34 AM Andrzej Hajda wrote: > > On 05.06.2019 09:04, Andrey Smirnov wrote: > > A very unfortunate aspect of tc_write()/tc_read() macro helpers is > > that they capture quite a bit of context around them and thus require > > the caller to have magic variables 'ret' and 'tc' as well as label > > 'err'. That makes a number of code paths rather counterintuitive and > > somewhat clunky, for example tc_stream_clock_calc() ends up being like > > this: > > > > int ret; > > > > tc_write(DP0_VIDMNGEN1, 32768); > > > > return 0; > > err: > > return ret; > > > > which is rather surprising when you read the code for the first > > time. Since those helpers arguably aren't really saving that much code > > and there's no way of fixing them without making them too verbose to > > be worth it change the driver code to not use them at all. > > > On the other side, error checking after every registry access is very > annoying and significantly augments the code, makes it redundant and > less readable. To avoid it one can cache error state, and do not perform > real work until the error is clear. For example with following accessor: > > void tc_write(struct tc_data *tc, u32 reg, u32 val){ > > int ret; > > if (tc->error) //This check is IMPORTANT > > return; > > ret =regmap_write(...); > > if (ret >= 0) > > return; > > tc->error = ret; > > dev_err(tc->dev, "Error writing register %#x\n", reg); > > } > > You can safely write code like: > > tc_write(tc, DP_PHY_CTRL, BGREN | PWR_SW_EN | PHY_A0_EN); > > tc_write(tc, DP0_PLLCTRL, PLLUPDATE | PLLEN); > > tc_write(tc, DP1_PLLCTRL, PLLUPDATE | PLLEN); > > if (tc->error) { > > tc->error = 0; > > goto err; > > } > > This is of course loose suggestion. > I am going to have to disagree with you on this one, unfortunately. Using regmap API explicitly definitely makes code more verbose, less readable or more annoying though? Not really from my perspective. With regmap code I know what the code is doing the moment I look at it, with the example above, not so much. I also find it annoying that I now have to remember the tricks that tc_write is pulling internally as well as be mindful of a global-ish error state object. My problem with original code was that a) it traded explicitness for conciseness in a an unfavorable way, which I still think is true for code above b) it didn't provide a comprehensive abstraction completely removing regmap API and still relied on things like regmap_update_bits() explicitly, making the code even more confusing (true for above example as well). I think this driver isn't big enough to have a dedicated person always working on it and it will mostly see occasional commits from somewhat random folks who are coming to the codebase fresh, so creating as little "institutional knowledge", so to speak, in a form of a custom exception-like mechanism and opting for explicit but verbose code seems like a preferable choice. Anyway, I get it that's it is a loose suggestion :-), just wanted to provide a detailed explanation why I'd rather not go that way. Thanks, Andrey Smirnov