From: Rob Herring <robh@kernel.org>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Frank Rowand <frowand.list@gmail.com>,
Pantelis Antoniou <pantelis.antoniou@konsulko.com>,
devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH 06/13] of: unittest: Merge of_unittest_apply{,_revert}_overlay_check()
Date: Thu, 27 Jul 2023 11:58:00 -0600 [thread overview]
Message-ID: <CAL_JsqKj5qRzddUYwpdv2Xe1cfub2+OeyVuVL0ha-cYS2uPkwA@mail.gmail.com> (raw)
In-Reply-To: <CAMuHMdWNnO3gyH-w7LmQ4T7pEANXtwTgdfx41+tSSP4oKs7zBQ@mail.gmail.com>
On Thu, Jul 27, 2023 at 8:04 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Rob,
>
> On Thu, Jul 20, 2023 at 8:31 PM Rob Herring <robh@kernel.org> wrote:
> > On Wed, Jul 19, 2023 at 05:00:06PM +0200, Geert Uytterhoeven wrote:
> > > of_unittest_apply_overlay_check() and the first part of
> > > of_unittest_apply_revert_overlay_check() are identical.
> > > Reduce code duplication by replacing them by two wrappers around a
> > > common helper.
> > >
> > > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > > ---
> > > drivers/of/unittest.c | 61 ++++++++++++++++---------------------------
> > > 1 file changed, 22 insertions(+), 39 deletions(-)
> >
> > I would do something like this instead:
> >
> > 8<-------------------------------------------------------------------
> > diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> > index a406a12eb208..a9635935aa26 100644
> > --- a/drivers/of/unittest.c
> > +++ b/drivers/of/unittest.c
> > @@ -2102,7 +2102,7 @@ static int __init of_unittest_apply_overlay(int overlay_nr, int *ovcs_id)
> > }
> >
> > /* apply an overlay while checking before and after states */
> > -static int __init of_unittest_apply_overlay_check(int overlay_nr,
> > +static int __init _of_unittest_apply_overlay_check(int overlay_nr,
> > int unittest_nr, int before, int after,
> > enum overlay_type ovtype)
> > {
> > @@ -2133,6 +2133,16 @@ static int __init of_unittest_apply_overlay_check(int overlay_nr,
> > return -EINVAL;
> > }
> >
> > + return ovcs_id;
> > +}
> > +
> > +static int __init of_unittest_apply_overlay_check(int overlay_nr,
> > + int unittest_nr, int before, int after,
> > + enum overlay_type ovtype)
> > +{
> > + int ovcs_id = _of_unittest_apply_overlay_check(overlay_nr, unittest_nr, before, after, ovtype);
> > + if (ovcs_id < 0)
> > + return ovcs_id;
> > return 0;
> > }
> >
> > @@ -2143,31 +2153,9 @@ static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
> > {
> > int ret, ovcs_id, save_ovcs_id;
> >
> > - /* unittest device must be in before state */
> > - if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
> > - unittest(0, "%s with device @\"%s\" %s\n",
> > - overlay_name_from_nr(overlay_nr),
> > - unittest_path(unittest_nr, ovtype),
> > - !before ? "enabled" : "disabled");
> > - return -EINVAL;
> > - }
> > -
> > - /* apply the overlay */
> > - ovcs_id = 0;
> > - ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id);
> > - if (ret != 0) {
> > - /* of_unittest_apply_overlay already called unittest() */
> > - return ret;
> > - }
> > -
> > - /* unittest device must be in after state */
> > - if (of_unittest_device_exists(unittest_nr, ovtype) != after) {
> > - unittest(0, "%s failed to create @\"%s\" %s\n",
> > - overlay_name_from_nr(overlay_nr),
> > - unittest_path(unittest_nr, ovtype),
> > - !after ? "enabled" : "disabled");
> > - return -EINVAL;
> > - }
> > + ovcs_id = _of_unittest_apply_overlay_check(overlay_nr, unittest_nr, before, after, ovtype);
> > + if (ovcs_id < 0)
> > + return ovcs_id;
> >
> > save_ovcs_id = ovcs_id;
> > ret = of_overlay_remove(&ovcs_id);
>
> That's what I had done first, before I realized I could reduce it by
> five more lines of code ;-)
>
> mine: 1 file changed, 22 insertions(+), 39 deletions(-)
> yours: 1 file changed, 14 insertions(+), 26 deletions(-)
Less change to review is also worthwhile.
> Anyway, you're the maintainer, so I can update my patch if you insist...
The other thing about this that I noticed is I recall gregkh not
liking the pattern where function parameters change what the function
does (e.g. do_x_or_y(bool do_y)).
So yes, I prefer mine.
Rob
next prev parent reply other threads:[~2023-07-27 17:58 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-19 15:00 [PATCH 00/13] of: overlay/unittest: Miscellaneous fixes and improvements Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 01/13] of: dynamic: Do not use "%pOF" while holding devtree_lock Geert Uytterhoeven
2023-07-19 23:02 ` Rob Herring
2023-07-20 21:30 ` Rob Herring
2023-07-27 13:42 ` Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 02/13] of: overlay: Call of_changeset_init() early Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 03/13] of: unittest: Fix overlay type in apply/revert check Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 04/13] of: unittest: Restore indentation in overlay_bad_add_dup_prop test Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 05/13] of: unittest: Improve messages and comments in apply/revert checks Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 06/13] of: unittest: Merge of_unittest_apply{,_revert}_overlay_check() Geert Uytterhoeven
2023-07-20 18:31 ` Rob Herring
2023-07-27 14:04 ` Geert Uytterhoeven
2023-07-27 17:58 ` Rob Herring [this message]
2023-07-19 15:00 ` [PATCH 07/13] of: unittest: Cleanup partially-applied overlays Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 08/13] of: unittest: Add separators to of_unittest_overlay_high_level() Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 09/13] of: overlay: unittest: Add test for unresolved symbol Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 10/13] of: unittest-data: Convert remaining overlay DTS files to sugar syntax Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 11/13] of: unittest-data: Fix whitespace - blank lines Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 12/13] of: unittest-data: Fix whitespace - indentation Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 13/13] of: unittest-data: Fix whitespace - angular brackets Geert Uytterhoeven
2023-07-20 18:37 ` [PATCH 00/13] of: overlay/unittest: Miscellaneous fixes and improvements Rob Herring
2023-07-27 19:34 ` Frank Rowand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAL_JsqKj5qRzddUYwpdv2Xe1cfub2+OeyVuVL0ha-cYS2uPkwA@mail.gmail.com \
--to=robh@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=geert@linux-m68k.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=pantelis.antoniou@konsulko.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).