| Message ID | 20200514121145.28737-6-jagan@amarulasolutions.com |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-amarula+bncBD7MFH7A7EEBBG7L6T2QKGQEJJACTJI@amarulasolutions.com> X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 99ECB3F077 for <linux-amarula@patchwork.amarulasolutions.com>; Thu, 14 May 2020 14:12:12 +0200 (CEST) Received: by mail-pf1-f197.google.com with SMTP id 126sf2490829pfd.10 for <linux-amarula@patchwork.amarulasolutions.com>; Thu, 14 May 2020 05:12:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1589458331; cv=pass; d=google.com; s=arc-20160816; b=rfUEaR1+M2eptCNilpjji/h705t+umycqfg9xIc8k38izPGy3zOL1dENbsabvGV0CG CUFCP1IERBABY+XYoc0R46ULFE6PAK9d1iP5Jfx3lUI7ScYF1Rum2y3ZwRlOPIq7lp1m alphK5v/G4QTYnMX0z767MkZ1X7IRkPavuaAMVlXW6AlExqvW/XpazmhIzxX1+4MAGCz LGi1NplOJKrmtgTpM/eFslNG3ijnGK9V+3LpnEFoz5noXjBVZjjkrHTAI9uIRF17x6Zy 0swRESx1TJJ/Evppjhy/nCEBIV2tBXCXYscj2fxEV0wzhxJ5dvSOJUuxnZkt726/pWNi 9W/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=nNrVBg89mChOHSXJdWq/hb5PfNR4LZqDDTKog2xluRs=; b=gi6xxwcRMFfizcRVGUt8MwEFew9GwHgPsWGIq7L2e1EppPe5pHSvo6hukdwif9XjOE SzWcCVkMLczvMahumtw/zBkBZn5YGnFsj37P8CP1jYI26i46nJ9/a/2W8RPcC+sl/M7z yzbJ16njPPiT6gqPmu9xv9CsXQTo2bpEJsuVOkVrO1PgYV4KMEr+tGcYi6ch+iI2VMNK gm0yoGP2MvsQbODqDWsP4oIjJ9roCKcupnvf/197kuSwODKdKxMej1D75MR/yHrkTOUM tXkL/OSbUPz6CiQy91OCk6Dnq4mV/5ou2dYSYy5tFFpK/C7DSxo5JfjLzSfbbTM/05EJ KUOA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=jb3r21E2; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=nNrVBg89mChOHSXJdWq/hb5PfNR4LZqDDTKog2xluRs=; b=MGe0j93Dfxi6bH0Ak1K0NG/xwAHIhrV4ZSHE7gcnLZZ8RLTreANHFNaceFFEvPMCAB eJGeOwCFQy2Oyw6On22+c9Bz02V7crYCowC2WQFyDl/13Zce+ZLKNcZaa/d7G1Drywkc uiVWxcKFM3AnTN27GeJOSd3n/2OGYfQ3JT5U8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=nNrVBg89mChOHSXJdWq/hb5PfNR4LZqDDTKog2xluRs=; b=rkBAjiRrTXWtbewp7RTiCkkZrPx7KnFHzbc4R4ocAvsyeB1I6SyWdUm8pdgb7OCmEb WtgIbhwLbv3I133QimyPQ6Zj6biz7ZcajXNvCemG5vlpToWYCHB+hx5dAyb7XkSaw/u1 pwCtXN3YO/YhYVqk/K5hCVzhKme12qzh6xnijg/l7gOp1V5vJE6bg80BVfI9MZbuGAzY +T3mQJoTsCZsAuzAkR5rq4DGrtsJLpm3YSgSypMqn501Jvw2HNMDtv0y1V1rZi/HrowL dn4bMgGmn9d1raKyGplxZQTME+bViAKONJ8Un7YBODCuJKQifyVJhdefZqZjKJVIMl48 oLow== X-Gm-Message-State: AOAM532hIGEuWK6rU5AAx1Cw4sBBhW2yHACKPXffPvy5a/mcTQdmMjx6 kHqtBRjfzafg6X89igkn03DxBXXm X-Google-Smtp-Source: ABdhPJzZlsslMwNWqwLvEZiSlpvay7QtRZQIy2rdsb3Jos5e2NP5d5+UEjcA4bLkRkf/wCWN8eyHDQ== X-Received: by 2002:a17:902:74cc:: with SMTP id f12mr3594189plt.119.1589458331393; Thu, 14 May 2020 05:12:11 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:8a8a:: with SMTP id p10ls1004929plo.11.gmail; Thu, 14 May 2020 05:12:11 -0700 (PDT) X-Received: by 2002:a17:902:8e8c:: with SMTP id bg12mr3863080plb.279.1589458330937; Thu, 14 May 2020 05:12:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589458330; cv=none; d=google.com; s=arc-20160816; b=YbMqdfL9fKma3jux/hfkTGrK47bgondUfg4Tk/bZ5v6cUiF7R0c8kQaCXX1lh9XF4J E4D+qqIo51l1zCGgHyDs8hZ5M0ojWp+GcOPKo4BrSVMTeJCMULjj06bZEDbYUdHzI5G9 XX37XEP9C15tDtRSF2Z0X4gFGYi4NHs1KHDWUZoiNnCiiGxQf8AKK8okc1xoxzbg+QJQ P2sX1or8PUNYCUN2r/Hz9NEuARkK7Rbs6EUMohsgu06yJtmiSL+olmtFBEVc0xsrUol4 N9BGDqCTzMD2G2/Kq3OpxRhYM4wkutAYeeAyXdOnd77t3MOIZ2b4EypsXcFwpoAdtEDM Rhwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=fxeerWO+ueh4IugH1YGq1cZPNbdvsKr2oC7ffVaVujI=; b=BNEXcJzoX7XmM7YDvpaWhoK8Xcd+IW5MgKfxdQqwKmHNsA+24iE8vaPHw0fU/p8AiT Ej6BkEAwGhee0Zrl2HxDidwrZq7wPiA9arsYhwd7KaesEy243DxOgU67Pe0OUdTWXIHB Na8pAeL7Zo1HUJVVl42KTV3NvhD91lYitx1cW8+MucDa1Ln+GZmnCIGmshXgaIgeVLHi Rn+RaN7JHyyHtR7ti5u6t2nwp3z0zFLbNksKgBKaZagrYgPgnRnq11yUM65J1f5yvTCl NJ2WtWnm93AJHuIbv0kuJ2efHUKB6PnYlGximkY72YPJvW7r2zAvJKAo5iArOv9/M9Iy 29QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=jb3r21E2; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id s2sor27921979pjp.29.2020.05.14.05.12.10 for <linux-amarula@amarulasolutions.com> (Google Transport Security); Thu, 14 May 2020 05:12:10 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:90a:a893:: with SMTP id h19mr39474558pjq.138.1589458330671; Thu, 14 May 2020 05:12:10 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:713c:4a0a:47eb:ffcd]) by smtp.gmail.com with ESMTPSA id r31sm2091050pgl.86.2020.05.14.05.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 05:12:09 -0700 (PDT) From: Jagan Teki <jagan@amarulasolutions.com> To: u-boot@lists.denx.de Cc: linux-amarula@amarulasolutions.com, Jagan Teki <jagan@amarulasolutions.com>, Simon Glass <sjg@chromium.org>, Vignesh R <vigneshr@ti.com>, Daniel Schwierzeck <daniel.schwierzeck@gmail.com> Subject: [PATCH 5/5] mtd: spi: Use IS_ENABLED to prevent ifdef Date: Thu, 14 May 2020 17:41:45 +0530 Message-Id: <20200514121145.28737-6-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514121145.28737-1-jagan@amarulasolutions.com> References: <20200514121145.28737-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=jb3r21E2; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: <linux-amarula.amarulasolutions.com> X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/post>, <mailto:linux-amarula@amarulasolutions.com> List-Help: <https://support.google.com/a/amarulasolutions.com/bin/topic.py?topic=25838>, <mailto:linux-amarula+help@amarulasolutions.com> List-Archive: <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/> List-Unsubscribe: <mailto:googlegroups-manage+476853432473+unsubscribe@googlegroups.com>, <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/subscribe> |
| Series |
sf: Cleanup
|
|
Commit Message
Jagan Teki
May 14, 2020, 12:11 p.m. UTC
Use IS_ENABLED to prevent ifdef in sf_probe.c
Cc: Simon Glass <sjg@chromium.org>
Cc: Vignesh R <vigneshr@ti.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
---
drivers/mtd/spi/sf_internal.h | 10 ++++++++++
drivers/mtd/spi/sf_probe.c | 17 ++++++++---------
2 files changed, 18 insertions(+), 9 deletions(-)
Comments
Am 14.05.20 um 14:11 schrieb Jagan Teki: > Use IS_ENABLED to prevent ifdef in sf_probe.c > > Cc: Simon Glass <sjg@chromium.org> > Cc: Vignesh R <vigneshr@ti.com> > Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com> > Signed-off-by: Jagan Teki <jagan@amarulasolutions.com> > --- > drivers/mtd/spi/sf_internal.h | 10 ++++++++++ > drivers/mtd/spi/sf_probe.c | 17 ++++++++--------- > 2 files changed, 18 insertions(+), 9 deletions(-) > > diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h > index 940b2e4c9e..544ed74a5f 100644 > --- a/drivers/mtd/spi/sf_internal.h > +++ b/drivers/mtd/spi/sf_internal.h > @@ -81,5 +81,15 @@ int spi_flash_cmd_get_sw_write_prot(struct spi_flash *flash); > #if CONFIG_IS_ENABLED(SPI_FLASH_MTD) > int spi_flash_mtd_register(struct spi_flash *flash); > void spi_flash_mtd_unregister(void); > +#else > +static inline int spi_flash_mtd_register(struct spi_flash *flash) > +{ > + return 0; > +} > + > +static inline void spi_flash_mtd_unregister(void) > +{ > +} > #endif > + > #endif /* _SF_INTERNAL_H_ */ > diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c > index 89e384901c..1e8744896c 100644 > --- a/drivers/mtd/spi/sf_probe.c > +++ b/drivers/mtd/spi/sf_probe.c > @@ -44,9 +44,8 @@ static int spi_flash_probe_slave(struct spi_flash *flash) > if (ret) > goto err_read_id; > > -#if CONFIG_IS_ENABLED(SPI_FLASH_MTD) > - ret = spi_flash_mtd_register(flash); > -#endif > + if (IS_ENABLED(CONFIG_SPI_FLASH_MTD)) > + ret = spi_flash_mtd_register(flash); you have to use CONFIG_IS_ENABLED() instead of IS_ENABLED() to also consider the existing CONFIG_SPL_SPI_FLASH_MTD option $ git grep -n SPI_FLASH_MTD -- drivers/mtd/spi/ drivers/mtd/spi/Kconfig:187:config SPI_FLASH_MTD drivers/mtd/spi/Kconfig:199:config SPL_SPI_FLASH_MTD > > err_read_id: > spi_release_bus(spi); > @@ -83,9 +82,9 @@ struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs, > > void spi_flash_free(struct spi_flash *flash) > { > -#if CONFIG_IS_ENABLED(SPI_FLASH_MTD) > - spi_flash_mtd_unregister(); > -#endif > + if (IS_ENABLED(CONFIG_SPI_FLASH_MTD)) > + spi_flash_mtd_unregister(); > + > spi_free_slave(flash->spi); > free(flash); > } > @@ -150,9 +149,9 @@ int spi_flash_std_probe(struct udevice *dev) > > static int spi_flash_std_remove(struct udevice *dev) > { > -#if CONFIG_IS_ENABLED(SPI_FLASH_MTD) > - spi_flash_mtd_unregister(); > -#endif > + if (IS_ENABLED(CONFIG_SPI_FLASH_MTD)) > + spi_flash_mtd_unregister(); > + > return 0; > } > >
On 15/05/2020 06.27, Stefan Roese wrote: > Hi Daniel, > > On 14.05.20 18:31, Daniel Schwierzeck wrote: >> >> >> Am 14.05.20 um 14:11 schrieb Jagan Teki: >>> Use IS_ENABLED to prevent ifdef in sf_probe.c >>> >>> Cc: Simon Glass <sjg@chromium.org> >>> Cc: Vignesh R <vigneshr@ti.com> >>> Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com> >>> Signed-off-by: Jagan Teki <jagan@amarulasolutions.com> >>> --- >>> drivers/mtd/spi/sf_internal.h | 10 ++++++++++ >>> drivers/mtd/spi/sf_probe.c | 17 ++++++++--------- >>> 2 files changed, 18 insertions(+), 9 deletions(-) >>> >>> diff --git a/drivers/mtd/spi/sf_internal.h >>> b/drivers/mtd/spi/sf_internal.h >>> index 940b2e4c9e..544ed74a5f 100644 >>> --- a/drivers/mtd/spi/sf_internal.h >>> +++ b/drivers/mtd/spi/sf_internal.h >>> @@ -81,5 +81,15 @@ int spi_flash_cmd_get_sw_write_prot(struct >>> spi_flash *flash); >>> #if CONFIG_IS_ENABLED(SPI_FLASH_MTD) >>> int spi_flash_mtd_register(struct spi_flash *flash); >>> void spi_flash_mtd_unregister(void); >>> +#else >>> +static inline int spi_flash_mtd_register(struct spi_flash *flash) >>> +{ >>> + return 0; >>> +} >>> + >>> +static inline void spi_flash_mtd_unregister(void) >>> +{ >>> +} >>> #endif >>> + >>> #endif /* _SF_INTERNAL_H_ */ >>> diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c >>> index 89e384901c..1e8744896c 100644 >>> --- a/drivers/mtd/spi/sf_probe.c >>> +++ b/drivers/mtd/spi/sf_probe.c >>> @@ -44,9 +44,8 @@ static int spi_flash_probe_slave(struct spi_flash >>> *flash) >>> if (ret) >>> goto err_read_id; >>> -#if CONFIG_IS_ENABLED(SPI_FLASH_MTD) >>> - ret = spi_flash_mtd_register(flash); >>> -#endif >>> + if (IS_ENABLED(CONFIG_SPI_FLASH_MTD)) >>> + ret = spi_flash_mtd_register(flash); >> >> you have to use CONFIG_IS_ENABLED() instead of IS_ENABLED() > > Just curious: I thought that those two are equivalent: > > IS_ENABLED(CONFIG_FOO) and > CONFIG_IS_ENABLED(FOO) > > Is this not the case? No. The latter must be used for the symbols FOO that also exist in a separate SPL_FOO variant, while the former must be used where the same Kconfig symbol is supposed to cover both SPL and U-Boot proper. The former "morally" expands to (morally, there's some some preprocessor trickery to deal with the fact that defined() doesn't work outside preprocessor conditionals) (defined(CONFIG_FOO) && CONFIG_FOO == 1) ? 1 : 0 If FOO is a proper boolean Kconfig symbol, CONFIG_FOO is either defined as 1 or undefined. But the above also works for the legacy things set in a board header, where CONFIG_FOO could be explicitly defined as 0 or 1. The CONFIG_IS_ENABLED(FOO) expands to exactly the same thing when building U-Boot proper. But for SPL, the expansion is instead (again, morally) (defined(CONFIG_SPL_FOO) && CONFIG_SPL_FOO == 1) ? CONFIG_SPL_FOO : 0 That should make it obvious why one needs a variant that doesn't want the CONFIG_ included in the argument; the CONFIG_IS_ENABLED macro needs to do token-pasting with either CONFIG_SPL_ or just CONFIG_. [Implementation-wise, the trick to make the above work both for macros that are not defined and those that are defined with the value 1 is to have helpers #define FIRST_ARGUMENT_1 blargh, #define second_arg(one, two, ...) two macro, then with the appropriate amount of indirections to make sure macros get expanded and tokens get concatenated in the right order, one does second_arg(EAT_AN_ARGUMENT_##${CONFIG_FOO} 1, 0) If CONFIG_FOO is a macro with the value 1, the above becomes second_arg(FIRST_ARGUMENT_1 1, 0) -> second_arg(blarg, 1, 0) -> 1 while if CONFIG_FOO is not defined, the token just "expands" to itself, so we get second_arg(FIRST_ARGUMENT_CONFIG_FOO 1, 0) where, since FIRST_ARGUMENT_CONFIG_FOO also doesn't expand further, we get the 0. The same works if CONFIG_FOO is defined to any value other than 1, as long as its expansion is something that is valid for token concatenation; in particular, if it has the value 0, one just gets second_arg(FIRST_ARGUMENT_0 1, 0) where again FIRST_ARGUMENT_0 doesn't expand further and provide another comma, so the 0 gets picked out.] second_arg(blarg, 1, 0) -> 1 ]
diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h index 940b2e4c9e..544ed74a5f 100644 --- a/drivers/mtd/spi/sf_internal.h +++ b/drivers/mtd/spi/sf_internal.h @@ -81,5 +81,15 @@ int spi_flash_cmd_get_sw_write_prot(struct spi_flash *flash); #if CONFIG_IS_ENABLED(SPI_FLASH_MTD) int spi_flash_mtd_register(struct spi_flash *flash); void spi_flash_mtd_unregister(void); +#else +static inline int spi_flash_mtd_register(struct spi_flash *flash) +{ + return 0; +} + +static inline void spi_flash_mtd_unregister(void) +{ +} #endif + #endif /* _SF_INTERNAL_H_ */ diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index 89e384901c..1e8744896c 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -44,9 +44,8 @@ static int spi_flash_probe_slave(struct spi_flash *flash) if (ret) goto err_read_id; -#if CONFIG_IS_ENABLED(SPI_FLASH_MTD) - ret = spi_flash_mtd_register(flash); -#endif + if (IS_ENABLED(CONFIG_SPI_FLASH_MTD)) + ret = spi_flash_mtd_register(flash); err_read_id: spi_release_bus(spi); @@ -83,9 +82,9 @@ struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs, void spi_flash_free(struct spi_flash *flash) { -#if CONFIG_IS_ENABLED(SPI_FLASH_MTD) - spi_flash_mtd_unregister(); -#endif + if (IS_ENABLED(CONFIG_SPI_FLASH_MTD)) + spi_flash_mtd_unregister(); + spi_free_slave(flash->spi); free(flash); } @@ -150,9 +149,9 @@ int spi_flash_std_probe(struct udevice *dev) static int spi_flash_std_remove(struct udevice *dev) { -#if CONFIG_IS_ENABLED(SPI_FLASH_MTD) - spi_flash_mtd_unregister(); -#endif + if (IS_ENABLED(CONFIG_SPI_FLASH_MTD)) + spi_flash_mtd_unregister(); + return 0; }