lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+4VgcKaL+B1yDG+X7HLGam5T5njgccp9ebCnQJwiv3V5w07ow@mail.gmail.com>
Date: Wed, 4 Dec 2024 09:49:53 +0800
From: Yu-Hsian Yang <j2anfernee@...il.com>
To: Jonathan Cameron <jic23@...nel.org>
Cc: Krzysztof Kozlowski <krzk@...nel.org>, avifishman70@...il.com, tmaimon77@...il.com, 
	tali.perry1@...il.com, venture@...gle.com, yuenn@...gle.com, 
	benjaminfair@...gle.com, lars@...afoo.de, robh@...nel.org, krzk+dt@...nel.org, 
	conor+dt@...nel.org, nuno.sa@...log.com, dlechner@...libre.com, 
	javier.carrasco.cruz@...il.com, andy@...nel.org, marcelo.schmitt@...log.com, 
	olivier.moysan@...s.st.com, mitrutzceclan@...il.com, 
	matteomartelli3@...il.com, alisadariana@...il.com, joao.goncalves@...adex.com, 
	marius.cristea@...rochip.com, mike.looijmans@...ic.nl, 
	chanh@...amperecomputing.com, KWLIU@...oton.com, yhyang2@...oton.com, 
	openbmc@...ts.ozlabs.org, linux-iio@...r.kernel.org, 
	devicetree@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1 2/2] iio: adc: add Nuvoton NCT720x ADC driver

Thank you for your comment.

Jonathan Cameron <jic23@...nel.org> 於 2024年11月9日 週六 下午9:45寫道:
>
> On Thu, 7 Nov 2024 08:41:21 +0800
> Yu-Hsian Yang <j2anfernee@...il.com> wrote:
>
> > Dear Krzysztof Kozlowski,
> >
> > Thank you for your response.
> >
> > Krzysztof Kozlowski <krzk@...nel.org> 於 2024年11月6日 週三 下午9:41寫道:
> > >
> > > On 06/11/2024 03:39, Eason Yang wrote:
> > > > Add Nuvoton NCT7201/NCT7202 system voltage monitor 12-bit ADC driver
> > > >
> > > > NCT7201/NCT7202 supports up to 12 analog voltage monitor inputs and up to
> > > > 4 SMBus addresses by ADDR pin. Meanwhile, ALERT# hardware event pins for
> > > > independent alarm signals, and the all threshold values could be set for
> > > > system protection without any timing delay. It also supports reset input
> > > > RSTIN# to recover system from a fault condition.
> > > >
> > > > Currently, only single-edge mode conversion and threshold events support.
> > > >
> > > > Signed-off-by: Eason Yang <j2anfernee@...il.com>
> > >
> > > ...
> > >
> > > > +
> > > > +static int nct720x_probe(struct i2c_client *client)
> > > > +{
> > > > +     const struct i2c_device_id *id = i2c_client_get_device_id(client);
> > > > +     struct nct720x_chip_info *chip;
> > > > +     struct iio_dev *indio_dev;
> > > > +     int ret;
> > > > +     u32 tmp;
> > > > +
> > > > +     indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
> > > > +     if (!indio_dev)
> > > > +             return -ENOMEM;
> > > > +     chip = iio_priv(indio_dev);
> > > > +
> > > > +     if (client->dev.of_node)
> > > > +             chip->type = (enum nct720x_chips)device_get_match_data(&client->dev);
> > > > +     else
> > > > +             chip->type = i2c_match_id(nct720x_id, client)->driver_data;
> > >
> > > I believe there is a I2C wrapper for above.
> > >
> >
> > Got it.
>
> Don't pass an enum value as data.  Pass a pointer to a structure that describes the particular
> variant.  The 0 value which tends to end up in enums is an error for device_get_match_data.
>

I would pass a pointer to the data structure not id to describe the
particular variant.
I would rewrite the code as below,

static const struct nct720x_adc_model_data nct7201_model_data = {
.model_name = "nct7201",
.channels = nct7201_channels,
.num_channels = ARRAY_SIZE(nct7201_channels),
.vin_max = 8,
};

static const struct nct720x_adc_model_data nct7202_model_data = {
.model_name = "nct7202",
.channels = nct7202_channels,
.num_channels = ARRAY_SIZE(nct7202_channels),
.vin_max = 12,
};

static const struct i2c_device_id nct720x_id[] = {
{ "nct7201", (kernel_ulong_t)&nct7201_model_data },
{ "nct7202", (kernel_ulong_t)&nct7202_model_data },
{ }
};
MODULE_DEVICE_TABLE(i2c, nct720x_id);

static const struct of_device_id nct720x_of_match[] = {
{
.compatible = "nuvoton,nct7201",
.data = &nct7201_model_data,
},
{
.compatible = "nuvoton,nct7202",
.data = &nct7202_model_data,
},
{ }
};
MODULE_DEVICE_TABLE(of, nct720x_of_match);

> >
> > > > +
> > > > +     chip->vin_max = (chip->type == nct7201) ? NCT7201_VIN_MAX : NCT7202_VIN_MAX;
> > > > +
> > > > +     ret = of_property_read_u32(client->dev.of_node, "read-vin-data-size", &tmp);
> > > > +     if (ret < 0) {
> > > > +             pr_err("read-vin-data-size property not found\n");
> > >
> > > Please use dev_xxx in your driver code.
> >
> > Got it.
> >
> > >
> > >
> > > Best regards,
> > > Krzysztof
> > >
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ