Re: [PATCH v2 05/15] spi: Remove code duplication in spi_add_device_locked()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- Subject: Re: [PATCH v2 05/15] spi: Remove code duplication in spi_add_device_locked()
- From: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
- Date: Tue, 11 Jul 2023 15:47:57 +0300
- Cc: Mark Brown <broonie@xxxxxxxxxx>, Cristian Ciocaltea <cristian.ciocaltea@xxxxxxxxxxxxx>, Yang Yingliang <yangyingliang@xxxxxxxxxx>, Amit Kumar Mahapatra via Alsa-devel <alsa-devel@xxxxxxxxxxxxxxxx>, Neil Armstrong <neil.armstrong@xxxxxxxxxx>, Tharun Kumar P <tharunkumar.pasumarthi@xxxxxxxxxxxxx>, Vijaya Krishna Nivarthi <quic_vnivarth@xxxxxxxxxxx>, Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx>, linux-spi@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, linux-amlogic@xxxxxxxxxxxxxxxxxxx, linux-mediatek@xxxxxxxxxxxxxxxxxxx, linux-arm-msm@xxxxxxxxxxxxxxx, linux-rockchip@xxxxxxxxxxxxxxxxxxx, linux-riscv@xxxxxxxxxxxxxxxxxxx, linux-stm32@xxxxxxxxxxxxxxxxxxxxxxxxxxxx, linux-trace-kernel@xxxxxxxxxxxxxxx, netdev@xxxxxxxxxxxxxxx, Sanjay R Mehta <sanju.mehta@xxxxxxx>, Radu Pirea <radu_nicolae.pirea@xxxxxx>, Nicolas Ferre <nicolas.ferre@xxxxxxxxxxxxx>, Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx>, Claudiu Beznea <claudiu.beznea@xxxxxxxxxxxxx>, Tudor Ambarus <tudor.ambarus@xxxxxxxxxx>, Serge Semin <fancer.lancer@xxxxxxxxx>, Shawn Guo <shawnguo@xxxxxxxxxx>, Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>, Pengutronix Kernel Team <kernel@xxxxxxxxxxxxxx>, Fabio Estevam <festevam@xxxxxxxxx>, NXP Linux Team <linux-imx@xxxxxxx>, Kevin Hilman <khilman@xxxxxxxxxxxx>, Jerome Brunet <jbrunet@xxxxxxxxxxxx>, Martin Blumenstingl <martin.blumenstingl@xxxxxxxxxxxxxx>, Matthias Brugger <matthias.bgg@xxxxxxxxx>, AngeloGioacchino Del Regno <angelogioacchino.delregno@xxxxxxxxxxxxx>, Andy Gross <agross@xxxxxxxxxx>, Bjorn Andersson <andersson@xxxxxxxxxx>, Konrad Dybcio <konrad.dybcio@xxxxxxxxxx>, Heiko Stuebner <heiko@xxxxxxxxx>, Palmer Dabbelt <palmer@xxxxxxxxxxx>, Paul Walmsley <paul.walmsley@xxxxxxxxxx>, Orson Zhai <orsonzhai@xxxxxxxxx>, Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>, Chunyan Zhang <zhang.lyra@xxxxxxxxx>, Alain Volmat <alain.volmat@xxxxxxxxxxx>, Maxime Coquelin <mcoquelin.stm32@xxxxxxxxx>, Alexandre Torgue <alexandre.torgue@xxxxxxxxxxx>, Max Filippov <jcmvbkbc@xxxxxxxxx>, Steven Rostedt <rostedt@xxxxxxxxxxx>, Masami Hiramatsu <mhiramat@xxxxxxxxxx>, Richard Cochran <richardcochran@xxxxxxxxx>
- In-reply-to: <20230711120133.45drgk46y4cz7aut@mercury.elektranox.org>
- Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
- References: <20230710154932.68377-1-andriy.shevchenko@linux.intel.com> <20230710154932.68377-6-andriy.shevchenko@linux.intel.com> <7557bada-3076-4d6e-a5c5-d368433706e2@sirena.org.uk> <ZK03rBqoQ0IZz617@smile.fi.intel.com> <20230711120133.45drgk46y4cz7aut@mercury.elektranox.org>
On Tue, Jul 11, 2023 at 02:01:33PM +0200, Sebastian Reichel wrote:
> On Tue, Jul 11, 2023 at 02:06:20PM +0300, Andy Shevchenko wrote:
> > On Mon, Jul 10, 2023 at 06:16:22PM +0100, Mark Brown wrote:
> > > On Mon, Jul 10, 2023 at 06:49:22PM +0300, Andy Shevchenko wrote:
...
> > > > - struct device *dev = ctlr->dev.parent;
> > > > -
> > > > - /* Chipselects are numbered 0..max; validate. */
> > > > - if (spi_get_chipselect(spi, 0) >= ctlr->num_chipselect) {
> > > > - dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, 0),
> > > > - ctlr->num_chipselect);
> > > > - return -EINVAL;
> > > > - }
> > > > -
> > > > - /* Set the bus ID string */
> > > > - spi_dev_set_name(spi);
> > >
> > > I see that this is duplicating spi_add_device() (and we really could do
> > > better with code sharing there I think) but I can't immediately see
> > > where the duplication that's intended to be elimiated is here - where
> > > else in the one call path that spi_add_device_locked() has would we do
> > > the above? Based on the changelog I was expecting to see some
> > > duplicated code in the function itself.
> >
> > Oh, by some reason Sebastian wasn't in this rather long Cc list.
> > Added him.
> >
> > Reading again I don't see any useful explanation why that piece of code has to
> > be duplicated among these two functions. It's 100% a copy.
> >
> > Sebastian, can you shed some light here?
>
> The patch in this thread is obviously wrong. It results in the
> checks never beeing called for spi_add_device_locked(). The copy is
> in spi_add_device() and those two are not calling into each other.
Ah, now I see, I missed __ in the name.
Thank you for opening my eyes!
> But it should be fine to move the code to the start of
> __spi_add_device(), which allows removing the duplication. In that
> case the code will be run with the add_lock held, which is probably
> what I was worried about two years ago. Looking at it again, the
> lock is held anyways in case of spi_add_device_locked().
Right, I will re-do that.
--
With Best Regards,
Andy Shevchenko
[Index of Archives]
[Linux Kernel]
[Linux ARM (vger)]
[Linux ARM MSM]
[Linux Omap]
[Linux Arm]
[Linux Tegra]
[Fedora ARM]
[Linux for Samsung SOC]
[eCos]
[Linux Fastboot]
[Gcc Help]
[Git]
[DCCP]
[IETF Announce]
[Security]
[Linux MIPS]
[Yosemite Campsites]
|