Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36821293rwd; Tue, 11 Jul 2023 06:13:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlFKoJcYVmeOegvJoAw0BT5exnvhxtgd+8w7SZibai4E9xSknbKSmRb01wcvpV5gelsVmfgk X-Received: by 2002:a17:906:7056:b0:982:487c:7508 with SMTP id r22-20020a170906705600b00982487c7508mr15157326ejj.38.1689081222832; Tue, 11 Jul 2023 06:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689081222; cv=none; d=google.com; s=arc-20160816; b=SC+aHq5sUVwwvM7a3e/H65tAz7LdrX4MlGT8F/98LwVpKyZYfoy7wSO0N63naaQJIf fvBdTsoWQ6zoodTwDXx+8T9wDi7XVY69bhhl12E9+JNm2aq9mAd8V7j4VAj4XSY/8CTk 4kDpNC2DSOT3ifmP9a5RAgZ2l5W7muMaRmB3SA8ilD9u1e0D47AzsLkvgQPq6CwYaEd7 nKyEFAmPYPRtUlLyLH4xBEk7TlsPOoEgGEpad1GjVSO/knWSVGm5tAPUXtbQOBH/3lwN odMT4Hyo2o3s89/x8OYZajQs/WRFZeMDxq9X2iJMDWvZVjWKWRabw/l7wAmUsI+Zt1dg nM8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=aMG+JctCM36xrS0sOwdO/+w4OaLry5nLx8CquSw/Pxc=; fh=iUWmgS0ZiAhUfpCJDYCiRdqXze9E18HT6fjZ6GVIeLI=; b=k6f7NOQztXEP44a7eOD2VoXFwbdfMzrYBPS5hMaPT0bVSeE6KpAZBFfqDKw9LsmdC4 pUw+6QhUl6fa3y29qCh+1o7S/mlmK6oFYF+i+v6rnNofedx70ca2stCBTPTDvVin9Mul 4+GqOOztQtpCFLW2/5G/tqTyprfVsluWQ63WQ8FY3B9n2+IcycYfkkHMTPEq2AGsn2Uh BZSZBKi0kHtT/6mVV0d4/4AmOZ0uk5vTpyu/hqBGFMjNj/S0V4ZjeOMbMcBKznQFauAf EBhCbwUjG3mWe+J5S/LXCJX87OKpvbDNqDvlyy8afbzo8f0f6tPtJ6N4uNXO8++Mr6lR CGBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gkXp+Uwh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qq17-20020a17090720d100b009938899a768si1906563ejb.530.2023.07.11.06.13.16; Tue, 11 Jul 2023 06:13:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gkXp+Uwh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231540AbjGKMsQ (ORCPT + 99 others); Tue, 11 Jul 2023 08:48:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbjGKMsP (ORCPT ); Tue, 11 Jul 2023 08:48:15 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B69135; Tue, 11 Jul 2023 05:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689079694; x=1720615694; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=nee+8F3UgjHiHBrgA29lPenNEyq01aBvrZNu0iQvTPs=; b=gkXp+Uwhe4htgOPQlLvPKwEYJ87AuGK4oRDPFCl9H/4KxahunwYnzCxt F5Shi4r69loeghlKwFItgM4JRNhTKAYIeC3k3n5qKRyvOjKCREg3QIwS2 wf3thcO/tqqYNqzv7/yv20tfFrNe6+31O3Xh5LUzwtXX8k9okVrbdyF1N T/DWP0DB0gKj5dBVyNj74CCfNytKU8jmDXKzsFcngkedEGDEvDInOTeLW w4WcqDxgjA/KmkKemgCgLCTm9bwkfQU0/s0CosD7fCxq3xcyJLxhIwEh0 FW9nDWoRdsIwwbo0z1p8qlpiYpjRDBS9WAOYjaN6QQgQ0zfPtN6eJTnrM Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="430694931" X-IronPort-AV: E=Sophos;i="6.01,196,1684825200"; d="scan'208";a="430694931" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2023 05:48:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="967787376" X-IronPort-AV: E=Sophos;i="6.01,196,1684825200"; d="scan'208";a="967787376" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga006.fm.intel.com with ESMTP; 11 Jul 2023 05:48:00 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qJCmb-001qkh-0z; Tue, 11 Jul 2023 15:47:57 +0300 Date: Tue, 11 Jul 2023 15:47:57 +0300 From: Andy Shevchenko To: Sebastian Reichel Cc: Mark Brown , Cristian Ciocaltea , Yang Yingliang , Amit Kumar Mahapatra via Alsa-devel , Neil Armstrong , Tharun Kumar P , Vijaya Krishna Nivarthi , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-riscv@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, Sanjay R Mehta , Radu Pirea , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Tudor Ambarus , Serge Semin , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Matthias Brugger , AngeloGioacchino Del Regno , Andy Gross , Bjorn Andersson , Konrad Dybcio , Heiko Stuebner , Palmer Dabbelt , Paul Walmsley , Orson Zhai , Baolin Wang , Chunyan Zhang , Alain Volmat , Maxime Coquelin , Alexandre Torgue , Max Filippov , Steven Rostedt , Masami Hiramatsu , Richard Cochran Subject: Re: [PATCH v2 05/15] spi: Remove code duplication in spi_add_device_locked() Message-ID: 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> <20230711120133.45drgk46y4cz7aut@mercury.elektranox.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230711120133.45drgk46y4cz7aut@mercury.elektranox.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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