diff mbox series

[v5,4/5] iio: amplifiers: hmc425a: use pointers in match table

Message ID 20240220153553.2432-4-mitrutzceclan@gmail.com (mailing list archive)
State Accepted
Headers show
Series Add support for LTC6373 | expand

Commit Message

Ceclan, Dumitru Feb. 20, 2024, 3:34 p.m. UTC
Change the match table to use pointers instead of device ids.
Remove type from state as it is not used anymore.

Signed-off-by: Dumitru Ceclan <mitrutzceclan@gmail.com>
---
 drivers/iio/amplifiers/hmc425a.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

Comments

Nuno Sá Feb. 21, 2024, 1:17 p.m. UTC | #1
On Tue, 2024-02-20 at 17:34 +0200, Dumitru Ceclan wrote:
> Change the match table to use pointers instead of device ids.
> Remove type from state as it is not used anymore.
> 
> Signed-off-by: Dumitru Ceclan <mitrutzceclan@gmail.com>
> ---

One comment (Jonathan might be able to address that while applying)... With that:

Reviewed-by: Nuno Sa <nuno.sa@analog.com>

>  drivers/iio/amplifiers/hmc425a.c | 29 +++++++++++++++--------------
>  1 file changed, 15 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/iio/amplifiers/hmc425a.c b/drivers/iio/amplifiers/hmc425a.c
> index 13e018a59637..77872e2dfdfe 100644
> --- a/drivers/iio/amplifiers/hmc425a.c
> +++ b/drivers/iio/amplifiers/hmc425a.c
> @@ -41,15 +41,14 @@ struct hmc425a_chip_info {
>  
>  struct hmc425a_state {
>  	struct	mutex lock; /* protect sensor state */
> -	struct	hmc425a_chip_info *chip_info;
> +	const struct	hmc425a_chip_info *chip_info;

Since you're doing this, I believe you should also constify hmc425a_chip_info_tbl[]
and mention it in the commit message.

- Nuno Sá
Jonathan Cameron Feb. 24, 2024, 5:44 p.m. UTC | #2
On Wed, 21 Feb 2024 14:17:22 +0100
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Tue, 2024-02-20 at 17:34 +0200, Dumitru Ceclan wrote:
> > Change the match table to use pointers instead of device ids.
> > Remove type from state as it is not used anymore.
> > 
> > Signed-off-by: Dumitru Ceclan <mitrutzceclan@gmail.com>
> > ---  
> 
> One comment (Jonathan might be able to address that while applying)... With that:
> 
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> 
> >  drivers/iio/amplifiers/hmc425a.c | 29 +++++++++++++++--------------
> >  1 file changed, 15 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/iio/amplifiers/hmc425a.c b/drivers/iio/amplifiers/hmc425a.c
> > index 13e018a59637..77872e2dfdfe 100644
> > --- a/drivers/iio/amplifiers/hmc425a.c
> > +++ b/drivers/iio/amplifiers/hmc425a.c
> > @@ -41,15 +41,14 @@ struct hmc425a_chip_info {
> >  
> >  struct hmc425a_state {
> >  	struct	mutex lock; /* protect sensor state */
> > -	struct	hmc425a_chip_info *chip_info;
> > +	const struct	hmc425a_chip_info *chip_info;  
> 
> Since you're doing this, I believe you should also constify hmc425a_chip_info_tbl[]
> and mention it in the commit message.
> 
Absolutely.  I've made that change and added a note on it to commit message.

> - Nuno Sá
>
diff mbox series

Patch

diff --git a/drivers/iio/amplifiers/hmc425a.c b/drivers/iio/amplifiers/hmc425a.c
index 13e018a59637..77872e2dfdfe 100644
--- a/drivers/iio/amplifiers/hmc425a.c
+++ b/drivers/iio/amplifiers/hmc425a.c
@@ -41,15 +41,14 @@  struct hmc425a_chip_info {
 
 struct hmc425a_state {
 	struct	mutex lock; /* protect sensor state */
-	struct	hmc425a_chip_info *chip_info;
+	const struct	hmc425a_chip_info *chip_info;
 	struct	gpio_descs *gpios;
-	enum	hmc425a_type type;
 	u32	gain;
 };
 
 static int gain_dB_to_code(struct hmc425a_state *st, int val, int val2, int *code)
 {
-	struct hmc425a_chip_info *inf = st->chip_info;
+	const struct hmc425a_chip_info *inf = st->chip_info;
 	int gain;
 
 	if (val < 0)
@@ -205,15 +204,6 @@  static const struct iio_chan_spec hmc425a_channels[] = {
 	HMC425A_CHAN(0),
 };
 
-/* Match table for of_platform binding */
-static const struct of_device_id hmc425a_of_match[] = {
-	{ .compatible = "adi,hmc425a", .data = (void *)ID_HMC425A },
-	{ .compatible = "adi,hmc540s", .data = (void *)ID_HMC540S },
-	{ .compatible = "adi,adrf5740", .data = (void *)ID_ADRF5740 },
-	{},
-};
-MODULE_DEVICE_TABLE(of, hmc425a_of_match);
-
 static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = {
 	[ID_HMC425A] = {
 		.name = "hmc425a",
@@ -261,9 +251,8 @@  static int hmc425a_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
-	st->type = (uintptr_t)device_get_match_data(&pdev->dev);
 
-	st->chip_info = &hmc425a_chip_info_tbl[st->type];
+	st->chip_info = device_get_match_data(&pdev->dev);
 	indio_dev->num_channels = st->chip_info->num_channels;
 	indio_dev->channels = st->chip_info->channels;
 	indio_dev->name = st->chip_info->name;
@@ -295,6 +284,18 @@  static int hmc425a_probe(struct platform_device *pdev)
 	return devm_iio_device_register(&pdev->dev, indio_dev);
 }
 
+/* Match table for of_platform binding */
+static const struct of_device_id hmc425a_of_match[] = {
+	{ .compatible = "adi,hmc425a",
+	  .data = &hmc425a_chip_info_tbl[ID_HMC425A]},
+	{ .compatible = "adi,hmc540s",
+	  .data = &hmc425a_chip_info_tbl[ID_HMC540S]},
+	{ .compatible = "adi,adrf5740",
+	  .data = &hmc425a_chip_info_tbl[ID_ADRF5740]},
+	{}
+};
+MODULE_DEVICE_TABLE(of, hmc425a_of_match);
+
 static struct platform_driver hmc425a_driver = {
 	.driver = {
 		.name = KBUILD_MODNAME,