From: Jiri Pirko <jiri@resnulli.us>
To: Or Gerlitz <gerlitz.or@gmail.com>
Cc: Linux Netdev List <netdev@vger.kernel.org>,
David Miller <davem@davemloft.net>,
idosch@mellanox.com, Elad Raz <eladr@mellanox.com>,
yotamg@mellanox.com
Subject: Re: [patch net-next v2 4/6] mlxsw: core: Implement temperature hwmon interface
Date: Sun, 29 Nov 2015 11:49:18 +0100 [thread overview]
Message-ID: <20151129104918.GC2194@nanopsycho.orion> (raw)
In-Reply-To: <CAJ3xEMgUt4a-Mq8DO0a_Vm-UYJsHsrxYyGh23=rSAiZ12S9oGQ@mail.gmail.com>
Sun, Nov 29, 2015 at 10:04:07AM CET, gerlitz.or@gmail.com wrote:
>[..]
>> +enum mlxsw_hwmon_attr_type {
>> + MLXSW_HWMON_ATTR_TYPE_TEMP,
>> + MLXSW_HWMON_ATTR_TYPE_TEMP_MAX,
>> +};
>> +
>> +static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon,
>> + enum mlxsw_hwmon_attr_type attr_type,
>> + unsigned int type_index, unsigned int num) {
>> + struct mlxsw_hwmon_attr *mlxsw_hwmon_attr;
>> + unsigned int attr_index;
>> +
>> + attr_index = mlxsw_hwmon->attrs_count;
>> + mlxsw_hwmon_attr = &mlxsw_hwmon->hwmon_attrs[attr_index];
>> +
>> + switch (attr_type) {
>> + case MLXSW_HWMON_ATTR_TYPE_TEMP:
>> + mlxsw_hwmon_attr->dev_attr.show = mlxsw_hwmon_temp_show;
>> + mlxsw_hwmon_attr->dev_attr.attr.mode = S_IRUGO;
>> + snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
>> + "temp%u_input", num + 1);
>> + break;
>> + case MLXSW_HWMON_ATTR_TYPE_TEMP_MAX:
>> + mlxsw_hwmon_attr->dev_attr.show = mlxsw_hwmon_temp_max_show;
>> + mlxsw_hwmon_attr->dev_attr.attr.mode = S_IRUGO;
>> + snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
>> + "temp%u_highest", num + 1);
>> + break;
>> + default:
>> + BUG();
>
>Guys, do we really have to crash the whole system just b/c somehow an unknown
>value propagated here during **init** time?
>
>I don't think so.
"default" case simply *cannot* happen. If it happens, it is a stack
corruption or some other fatal problem. I believe that BUG is
appropriate at these cases.
>
>> +
>> + mlxsw_hwmon_attr->type_index = type_index;
>> + mlxsw_hwmon_attr->hwmon = mlxsw_hwmon;
>> + mlxsw_hwmon_attr->dev_attr.attr.name = mlxsw_hwmon_attr->name;
>> + sysfs_attr_init(&mlxsw_hwmon_attr->dev_attr.attr);
>> +
>> + mlxsw_hwmon->attrs[attr_index] = &mlxsw_hwmon_attr->dev_attr.attr;
>> + mlxsw_hwmon->attrs_count++;
>> +}
>> +
>
>[...]
>> +int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
>> + const struct mlxsw_bus_info *mlxsw_bus_info,
>> + struct mlxsw_hwmon **p_hwmon)
>> +{
>> + struct mlxsw_hwmon *mlxsw_hwmon;
>> + struct device *hwmon_dev;
>> + int err;
>> +
>> + mlxsw_hwmon = kzalloc(sizeof(*mlxsw_hwmon), GFP_KERNEL);
>> + if (!mlxsw_hwmon)
>> + return -ENOMEM;
>> + mlxsw_hwmon->core = mlxsw_core;
>> + mlxsw_hwmon->bus_info = mlxsw_bus_info;
>> +
>> + err = mlxsw_hwmon_temp_init(mlxsw_hwmon);
>> + if (err)
>> + goto err_temp_init;
>> +
>> + mlxsw_hwmon->groups[0] = &mlxsw_hwmon->group;
>> + mlxsw_hwmon->group.attrs = mlxsw_hwmon->attrs;
>> +
>> + hwmon_dev = devm_hwmon_device_register_with_groups(mlxsw_bus_info->dev,
>> + "mlxsw",
>> + mlxsw_hwmon,
>> + mlxsw_hwmon->groups);
>> + if (IS_ERR(hwmon_dev)) {
>> + err = PTR_ERR(hwmon_dev);
>> + goto err_hwmon_register;
>> + }
>> +
>> + mlxsw_hwmon->hwmon_dev = hwmon_dev;
>> + *p_hwmon = mlxsw_hwmon;
>> + return 0;
>> +
>> +err_hwmon_register:
>> +err_temp_init:
>> + kfree(mlxsw_hwmon);
>> + return err;
>> +}
>> +
next prev parent reply other threads:[~2015-11-29 10:49 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-27 12:45 [patch net-next v2 0/6] mlxsw: driver update Jiri Pirko
2015-11-27 12:45 ` [patch net-next v2 1/6] mlxsw: reg: Add Management LED Control register definition Jiri Pirko
2015-11-27 12:45 ` [patch net-next v2 2/6] mlxsw: spectrum: Add support for port identification Jiri Pirko
2015-11-27 12:45 ` [patch net-next v2 3/6] mlxsw: reg: Add definition of temperature management registers Jiri Pirko
2015-11-27 12:45 ` [patch net-next v2 4/6] mlxsw: core: Implement temperature hwmon interface Jiri Pirko
2015-11-29 9:04 ` Or Gerlitz
2015-11-29 10:49 ` Jiri Pirko [this message]
2015-12-02 22:05 ` Or Gerlitz
2015-12-02 22:25 ` Jiri Pirko
2015-12-02 22:28 ` David Miller
2015-12-02 22:35 ` Jiri Pirko
2015-12-02 23:37 ` David Miller
2015-12-03 8:19 ` Jiri Pirko
2015-12-03 9:32 ` Or Gerlitz
2015-12-03 9:55 ` Jiri Pirko
2015-11-27 12:45 ` [patch net-next v2 5/6] mlxsw: reg: Add definition of fan management registers Jiri Pirko
2015-11-27 12:45 ` [patch net-next v2 6/6] mlxsw: core: Implement fan control using hwmon Jiri Pirko
2015-11-30 20:06 ` [patch net-next v2 0/6] mlxsw: driver update David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151129104918.GC2194@nanopsycho.orion \
--to=jiri@resnulli.us \
--cc=davem@davemloft.net \
--cc=eladr@mellanox.com \
--cc=gerlitz.or@gmail.com \
--cc=idosch@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=yotamg@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox