Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1685389ybh; Fri, 13 Mar 2020 05:43:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuOmyFT2IUuHk1rIzksAOTaXKHCfPYWrhWcJ3TrtX29jCjgh86oX8kiFNj+GuQouWvo2J6i X-Received: by 2002:a9d:1708:: with SMTP id i8mr10823532ota.250.1584103380018; Fri, 13 Mar 2020 05:43:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584103380; cv=none; d=google.com; s=arc-20160816; b=AT7jLnh+DexdwOBUCtMC6ssgWtNnTyYM+o6zCsAs940RsGT37to0q8DcxZV8ZFEYqW N1Qi3HZOoL/NWCJfNiWLGpD42rKnFe6lAGin6iAy3KYhgTAGqVDEErILNYB3zKaasgo+ EEiytEUvN/m3SbKE7HUqTPe9yt4+vNPDdj5OiY2HXaKUqaU6+R0rGDw7187G7I3wFV2a tYNYDUrcWc0IBKfr2Is9IHiTqB/eglhojOd+DzTg3Y/BMw5XvNDmSTZXdB61gmSUle6o aztW6lRzmq5bt2aPuKC1322KTc1UE0tKQM6JJW5Qk6BAZ+46RGnECRvGi8DF58tOS/NB 1Tpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=R9ymAk5R0b2SJ6yBU86YmRMamhCCA5C3O5fTYML312E=; b=N7/R2uBc20PHv/PdimdKLkka36jaPsaJhyoAFvF5ZwwEsMYp8d5LC6E23etfIrgAkg HBFFTYPdwBGQz2skxcqewWecEIvR6R55zBegLNquR9iyts9ubaBODXpHs0mywSkQV7LW kHrHOUF7ke685ct7dyznBPanMuOuq3nLjjGBcVw0RbSqpxPaBnSi3kW1qbXJ8dekoCIo AYoygJwBg8UciJXzDGmB66vulNpyAYzRrtJi8RoOEwi5jij1PGsAiBIAe8ARFqwZOIeo 5xoJ1u6w94h1jrN4xNau2ZTx/h6tk/7tm27qVhRPmABSVvFRGsNo9oUPxgb9VYssUOwg 8HnA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p17si5587538ota.232.2020.03.13.05.42.46; Fri, 13 Mar 2020 05:43:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbgCMMmW (ORCPT + 99 others); Fri, 13 Mar 2020 08:42:22 -0400 Received: from sauhun.de ([88.99.104.3]:51458 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726681AbgCMMmV (ORCPT ); Fri, 13 Mar 2020 08:42:21 -0400 Received: from localhost (p54B3314F.dip0.t-ipconnect.de [84.179.49.79]) by pokefinder.org (Postfix) with ESMTPSA id ED39D2C1ED4; Fri, 13 Mar 2020 13:42:17 +0100 (CET) Date: Fri, 13 Mar 2020 13:42:14 +0100 From: Wolfram Sang To: Geert Uytterhoeven Cc: Wolfram Sang , Linux I2C , Linux-Renesas , linux-i3c@lists.infradead.org, Kieran Bingham , Niklas =?utf-8?Q?S=C3=B6derlund?= , Luca Ceresoli , Jacopo Mondi , Laurent Pinchart , Vladimir Zapolskiy , Linux Kernel Mailing List , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" Subject: Re: [RFC PATCH 7/7] i2c: core: hand over reserved devices when requesting ancillary addresses Message-ID: <20200313124214.GA1299@ninjato> References: <20200220172403.26062-1-wsa+renesas@sang-engineering.com> <20200220172403.26062-8-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="d6Gm4EdcadzBjdND" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --d6Gm4EdcadzBjdND Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > > @@ -984,7 +986,21 @@ struct i2c_client *i2c_new_ancillary_device(struct= i2c_client *client, > > of_property_read_u32_index(np, "reg", i, &addr); > > } > > > > - dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name,= addr); > > + dev_info(adapter_dev, "Address for %s : 0x%x\n", name, addr); > > + > > + /* No need to scan muxes, siblings must sit on the same adapter= */ > > + reserved_dev =3D device_find_child(adapter_dev, &addr, __i2c_ch= eck_addr_busy); > > + reserved_client =3D i2c_verify_client(reserved_dev); > > + > > + if (reserved_client) { > > + if (reserved_client->dev.of_node !=3D np || > > + strcmp(reserved_client->name, I2C_RESERVED_DRV_NAME= ) !=3D 0) > > + return ERR_PTR(-EBUSY); >=20 > Missing put_device(reserved_dev). Actually, I think the code could even be like this: struct i2c_client *reserved_client =3D NULL; ... reserved_dev =3D device_find_child(adapter_dev, &addr, __i2c_check_addr_bu= sy); if (reserved_dev) { reserved_np =3D reserved_dev->of_node; reserved_client =3D i2c_verify_client(reserved_dev); put_device(reserved_dev); } if (reserved_client) { if (reserved_np !=3D np || strcmp(reserved_client->name, I2C_RESERVED_DRV_NAME) !=3D 0) return ERR_PTR(-EBUSY); strlcpy(reserved_client->name, I2C_DUMMY_DRV_NAME, sizeof(client->name)); return reserved_client; } return i2c_new_dummy_device(client->adapter, addr); We put the device early - as soon we don't access the struct anymore. I think we don't need the refcnt any further because what we are doing here is to hand over the initial refcnt from the core to the requesting driver. We turn the device from "reserved" (internally managed) to "dummy" (managed by the driver). So, I think the code is okay regarding the struct device. I will have a second look when it comes to concurrency problems regarding the struct i2c_client, though. > (perhaps i2c_verify_client() checking dev was not such a great idea, as > callers need to act on dev && !verified anyway?) Yeah, since I refactored the ACPI code as well, patch 1 from this series can probably go. Thanks again for your review, Geert! --d6Gm4EdcadzBjdND Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEOZGx6rniZ1Gk92RdFA3kzBSgKbYFAl5rf6IACgkQFA3kzBSg KbbLIw/+MOFwZSkWXt3ikwM+7rKei/WFEDfa/TZK7lKKvujaNfalPdxSx8w7M5dc V5uUDpEeCiJAn+TO+vOv+i5McITg+GDMiUQvbIqAtzVh+2jqNEkJIaMz+5wlefWG hcpujZdvPfrQNPf1FM77HO0WI9oChGBJkMb9tLbzm5yHLYh4zMq0aK+Z+oZQ7441 Lz2t2Yp+u4ikEHCvZWQVzOfyGRb2r/4nI5VuLbk8BhnlctKB3ALytdGws0QSctjH qPz0ePJQ4kXQ/Ch1oVOh9LfTGRGlk3hA2Sa1G0Kk9t42e+C2DmFWh8AYV16kZ8n7 8MF/mUVBrebEzijOyDcUbBt9LYJwr+lsuej94/afVqk68b+s/cal2ZTYjNrX5QM3 /FNYqVV/tvmzmxPoO93IxFBPYethKY7i0jFgflmkzFhWGZv2H6UyU9U0UbH0dDlC Cw8hjC1de2zxLP2xezv2vv5DH7Py1SFDfAU4xc9Xh/7HQFE9kLYbESG9cEh7mWLU FC6T9KRrrzkkFNn0cCo0wqmqn+yrA5a9YGkTfQg733bxB0DQINcfo7m7FQPiS1OY 7ZxNfj9IVIpOShOi+/26bTkj8AemRPnRCy9MAHREFza55LU+7GGDkHQJKDqKZI2q 6oI1uERpxeyZoQMTEhRiR8IM2CGy9LtL3ZGe11+NI6aXGe+hdL4= =VJ9d -----END PGP SIGNATURE----- --d6Gm4EdcadzBjdND--