Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752014AbcDOXKF (ORCPT ); Fri, 15 Apr 2016 19:10:05 -0400 Received: from mail-he1eur01on0096.outbound.protection.outlook.com ([104.47.0.96]:23037 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751751AbcDOXJ7 convert rfc822-to-8bit (ORCPT ); Fri, 15 Apr 2016 19:09:59 -0400 X-Greylist: delayed 24223 seconds by postgrey-1.27 at vger.kernel.org; Fri, 15 Apr 2016 19:09:57 EDT From: Peter Rosin To: Wolfram Sang , Peter Rosin CC: "linux-kernel@vger.kernel.org" , "Jonathan Corbet" , Peter Korsgaard , Guenter Roeck , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , "Peter Meerwald" , Antti Palosaari , "Mauro Carvalho Chehab" , Rob Herring , "Frank Rowand" , Grant Likely , Andrew Morton , Greg Kroah-Hartman , "David S. Miller" , "Kalle Valo" , Joe Perches , Jiri Slaby , Daniel Baluta , Adriana Reus , Lucas De Marchi , "Matt Ranostay" , Krzysztof Kozlowski , Terry Heo , Hans Verkuil , Arnd Bergmann , Tommi Rantala , "linux-i2c@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-iio@vger.kernel.org" , "linux-media@vger.kernel.org" , "devicetree@vger.kernel.org" Subject: Re: [PATCH v6 01/24] i2c-mux: add common data for every i2c-mux instance Thread-Topic: [PATCH v6 01/24] i2c-mux: add common data for every i2c-mux instance Thread-Index: AdGXLqvA/rHosQFhRii7VTuT90Zy0g== Date: Fri, 15 Apr 2016 15:52:55 +0000 Message-ID: Accept-Language: en-US, sv-SE Content-Language: sv-SE X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: the-dreams.de; dkim=none (message not signed) header.d=none;the-dreams.de; dmarc=none action=none header.from=axentia.se; x-originating-ip: [217.210.101.82] x-ms-office365-filtering-correlation-id: 02b61b12-9928-4de2-b813-08d365460319 x-microsoft-exchange-diagnostics: 1;AM4PR02MB1297;5:oAIZdmnMkpA9yoeIMBhlcAMLC6huHWrfpiQJEUHgkkxrVpsE1L1x/0GiT8oOysC08ziYnm0A4G1ppG+sW2ff8lYwN7zHyAvbkHeyLOA7UY3y8P5jgHvp74ExdoyB8a9v6/oMAD8JQ7Ur4a8M2oBVIA==;24:cV0kyzlnJXxsqRBieJ6YOANh/3wiibemSmaCgj4hr9ZTUfCKkmhRs5HrJ2DO9MsAJGwwaQP6/7hfJQBXfaonEK+DZOEL8KVRwx0Zn1jEnBo=;23:UnTX97nOrthSHlRkXCULZ4ztfeZz4a8Ct90L7XuWP8fKFVS/hgM7x3MWyBLT+EvhAKRUBMGnBtVrrhflgCn6WhfdTFOtakxvKRGdeJhCMhv9kx8taOcZvy9TBNqXoQ1JAoJPqgzMotU1jwWdDejGje0zO80RApzMh5gY0FfUXka71HDBiAHewKOCkof6krdL x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM4PR02MB1297; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(9101521026)(6040130)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041046)(6043046);SRVR:AM4PR02MB1297;BCL:0;PCL:0;RULEID:;SRVR:AM4PR02MB1297; x-forefront-prvs: 0913EA1D60 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(24454002)(15975445007)(9686002)(77096005)(2900100001)(2906002)(10400500002)(11100500001)(5002640100001)(5008740100001)(5003600100002)(5004730100002)(50986999)(3660700001)(81166005)(3280700002)(54356999)(74482002)(189998001)(76576001)(74316001)(92566002)(19580395003)(6116002)(87936001)(33656002)(1220700001)(66066001)(1096002)(586003)(86362001)(4326007)(102836003)(5001770100001)(3846002)(122556002)(7059030)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM4PR02MB1297;H:AM4PR02MB1299.eurprd02.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Apr 2016 15:52:55.9911 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4ee68585-03e1-4785-942a-df9c1871a234 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR02MB1297 X-OriginatorOrg: axentia.se Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4009 Lines: 86 Wolfram Sang wrote: > > > wonder even more if we couldn't supply num_adapters to i2c_mux_alloc() > > > and reserve the memory statically. i2c busses are not > > > dynamic/hot-pluggable so that should be good enough? > > > > Yes, that would work, but it would take some restructuring in some of > > the drivers that currently don't know how many child adapters they > > are going to need when they call i2c_mux_alloc. > > Which ones? If you look at i2c-mux-reg.c, it currently allocates its private struct regmux, then fills it with various platform things and then when it knows how many children it needs it allocates them. After v6 it first allocates a mux core and private struct regmux in one go using i2c_mux_alloc, then continues in much the same way as before. If the number of children is needed for the i2c_mux_alloc call, then this is certainly doable, and it would probably not be all that bad, but the simplest approach would probably be to allocate the private struct regmux first, then dig through the platform data, then allocate the mux core when the number of children is known. Which would still be two allocations separated by the platform data dig. So, your suggestion would basically move the mux core allocation from generally being done early together with other private data to later when the driver has figured out how many children it's going to create. The restructuring I thought about is needed if the intention of this was to reduce number of allocations, but maybe you just wanted what I described above? Because what I did in v6 and what you are suggesting is quite similar in complexity, but your version has the advantage of not having the need for realloc. So, I have made this change locally (and the adapters->num_adapters change) and I like it. I haven't even compile-tested it yet though, but I'll get back when I have done some testing. > > Because you thought about removing i2c_mux_reserve_adapters completely, > > and not provide any means of adding more adapters than specified in > > the i2c_mux_alloc call, right? > > Yes. I assumed I2C to be static enough that such information is known in > advance. > > > > Ignoring the 80 char limit here makes the code more readable. > > > > That is only true if you actually have more than 80 characters, so I don't > > agree. Are you adamant about it? (I'm not) > > No. Keep it if you prefer it. > > > >> +EXPORT_SYMBOL_GPL(i2c_mux_one_adapter); > > > > > > Are you sure the above function pays off? Its argument list is very > > > complex and it doesn't save a lot of code. Having seperate calls is > > > probably more understandable in drivers? Then again, I assume it makes > > > the conversion of existing drivers easier. > > > > I added it in v4, you can check earlier versions if you like. Without > > it most gate-muxes (i.e. typically the muxes in drivers/media) grew > > since the i2c_add_mux_adapter call got replaced by two calls, i.e. > > i2c_mux_alloc followed by i2c_max_add_adapter, and coupled with > > error checks made it look more complex than before. So, this wasn't > > much of a cleanup from the point of those drivers. > > Hmm, v3 didn't have the driver patches posted with it. Can you push it > to your branch? I am also not too strong with this one, but having a > look how it looks without would be nice. Although I'm not sure what you meant by "driver patches", I have pushed mux-core-and-locking-2 and mux-core-and-locking-3 to https://github.com/peda-r/i2c-mux/ (note that these are the branches as they where when I posted v2 and v3 to the list, i.e. w/o fixups) Those early versions updated all drivers with each change, making each patch big, so if that was what you meant by missing "driver patches" then there simply were no driver patches. If you meant the follow-up patches to relax locking in the media drivers etc, I only compile-tested them using throwaway branches back then (if I even had branches). So, I don't have anything ready to push, sorry. Cheers, Peter