From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7670E171C5 for ; Mon, 4 Dec 2023 11:46:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LYZOekNS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99456C433C8; Mon, 4 Dec 2023 11:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701690391; bh=i1+VKeSNTBMfL+Jw9GhDsIITBUtuYP9Ee/ts7oDwFgg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LYZOekNSEYjZHt0q1vMfNanrbaTZwFa3bfc1jqH/fiIipmhRFHY14gN7d2UaeUqYR kFmE4PSCKESYlxK6Ze6RMrI+/P8eaVT0khlLEZkpqzVBn6lL58zjooUFS/uIj++YGJ sfFo884yHwHHXfkZDfNcdrcNgoB7Y1nkyB0NcsxM9rztyQHw/ylE4SM6CmK9+QVI7W Kwqgs8iKN6wGgJMqa+1YUa/g2dXrPqBJa+McF/UNmMDY8+3OABYdYctiN0A2DEaVce LJpLJB1f8JHUBDKKqtImQ+k1vnFcqt7aehSxnSl/FYyFQQI/BfvYBYB+ls9WaiDz6d OA5xATpMcvLGQ== Date: Mon, 4 Dec 2023 11:46:23 +0000 From: Jonathan Cameron To: Petre Rodan Cc: Jonathan Cameron , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Lars-Peter Clausen , Andy Shevchenko , Angel Iglesias , Matti Vaittinen , Andreas Klinger , Rob Herring , Krzysztof Kozlowski Subject: Re: [PATCH v3 2/2] iio: pressure: driver for Honeywell HSC/SSC series pressure sensors Message-ID: <20231204114623.3aaa98d2@jic23-huawei> In-Reply-To: References: <20231126102721.15322-1-petre.rodan@subdimension.ro> <20231126183334.625d2d8b@jic23-huawei> <20231201182453.00005673@Huawei.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 2 Dec 2023 18:01:55 +0200 Petre Rodan wrote: > Hello! > > On Fri, Dec 01, 2023 at 06:24:53PM +0000, Jonathan Cameron wrote: > > > > > +static int hsc_spi_probe(struct spi_device *spi) > > > > > +{ > > > > > + struct iio_dev *indio_dev; > > > > > + struct hsc_data *hsc; > > > > > + struct device *dev = &spi->dev; > > > > > + > > > > > + indio_dev = devm_iio_device_alloc(dev, sizeof(*hsc)); > > > > > + if (!indio_dev) > > > > > + return -ENOMEM; > > > > > + > > > > > + hsc = iio_priv(indio_dev); > > > > > + hsc->xfer = hsc_spi_xfer; > > > > > > > > Also, pass the callback and spi->dev into hsc probe. Easy to use > > > > a container_of() to get back to the struct spi_device *spi > > > > > > I'd rather simply pass along the client struct. > > > > > > > I don't like the fact it has to be a void * > > > > The core code has no idea what is in there. At least we constraint it > > somewhat with a struct device. > > but ... > that is the nice part. the core code never needs to know what exactly is behind > that pointer, since it only gets used by the i2c/spi module that provided that > pointer in the first place. I've never seen a better use of void * :) > > I could define a > > struct client_handle; > > in the .h, use a pointer to that that as function argument, do a lot of > castings, but I feel like it's still a void * with extra steps. Usual trick for this is either use struct device and container_of or an anonymous union wrapped up in a struct. struct hsc_client_handle { union { struct i2c_client *i2c_client; struct spithingy *spi_client; }; }; Then assign appropriate element and pass the containing struct around. No casting needed. Aim is to define it as a constrained type that can only take one or the other of the types in the union. Jonathan > > cheers, > peter >