linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org, "Václav Kubernát" <kubernat@cesnet.cz>
Cc: lkp@intel.com, kbuild-all@lists.01.org,
	"Václav Kubernát" <kubernat@cesnet.cz>,
	"Jean Delvare" <jdelvare@suse.com>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Jonathan Corbet" <corbet@lwn.net>,
	linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/5] hwmon: (max31790) Rework to use regmap
Date: Wed, 17 Mar 2021 08:12:40 +0300	[thread overview]
Message-ID: <20210317051239.GW2087@kadam> (raw)
In-Reply-To: <20210316175503.1003051-1-kubernat@cesnet.cz>

[-- Attachment #1: Type: text/plain, Size: 10142 bytes --]

Hi "Václav,

url:    https://github.com/0day-ci/linux/commits/V-clav-Kubern-t/hwmon-max31790-Rework-to-use-regmap/20210317-015931
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
config: x86_64-randconfig-m001-20210316 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/hwmon/max31790.c:263 max31790_fan_is_visible() warn: impossible condition '(fan_config < 0) => (0-255 < 0)'
drivers/hwmon/max31790.c:337 max31790_write_pwm() warn: impossible condition '(fan_config < 0) => (0-255 < 0)'
drivers/hwmon/max31790.c:372 max31790_pwm_is_visible() warn: impossible condition '(fan_config < 0) => (0-255 < 0)'

vim +263 drivers/hwmon/max31790.c

54187ff9d766b2 Guenter Roeck   2016-07-01  257  static umode_t max31790_fan_is_visible(const void *_data, u32 attr, int channel)
195a4b4298a795 Il Han          2015-08-30  258  {
54187ff9d766b2 Guenter Roeck   2016-07-01  259  	const struct max31790_data *data = _data;
2c8602cfaeab63 Václav Kubernát 2021-03-16  260  	struct regmap *regmap = data->regmap;
2c8602cfaeab63 Václav Kubernát 2021-03-16  261  	u8 fan_config = read_reg_byte(regmap, MAX31790_REG_FAN_CONFIG(channel % NR_CHANNEL));
2c8602cfaeab63 Václav Kubernát 2021-03-16  262  
2c8602cfaeab63 Václav Kubernát 2021-03-16 @263  	if (fan_config < 0)
                                                            ^^^^^^^^^^^^^^
A u8 can't be negative.

2c8602cfaeab63 Václav Kubernát 2021-03-16  264  		return 0;
54187ff9d766b2 Guenter Roeck   2016-07-01  265  
54187ff9d766b2 Guenter Roeck   2016-07-01  266  	switch (attr) {
54187ff9d766b2 Guenter Roeck   2016-07-01  267  	case hwmon_fan_input:
54187ff9d766b2 Guenter Roeck   2016-07-01  268  	case hwmon_fan_fault:
54187ff9d766b2 Guenter Roeck   2016-07-01  269  		if (channel < NR_CHANNEL ||
54187ff9d766b2 Guenter Roeck   2016-07-01  270  		    (fan_config & MAX31790_FAN_CFG_TACH_INPUT))
dc8dbb4d7672b7 Guenter Roeck   2018-12-10  271  			return 0444;
54187ff9d766b2 Guenter Roeck   2016-07-01  272  		return 0;
54187ff9d766b2 Guenter Roeck   2016-07-01  273  	case hwmon_fan_target:
54187ff9d766b2 Guenter Roeck   2016-07-01  274  		if (channel < NR_CHANNEL &&
54187ff9d766b2 Guenter Roeck   2016-07-01  275  		    !(fan_config & MAX31790_FAN_CFG_TACH_INPUT))
dc8dbb4d7672b7 Guenter Roeck   2018-12-10  276  			return 0644;
54187ff9d766b2 Guenter Roeck   2016-07-01  277  		return 0;
54187ff9d766b2 Guenter Roeck   2016-07-01  278  	default:
54187ff9d766b2 Guenter Roeck   2016-07-01  279  		return 0;
195a4b4298a795 Il Han          2015-08-30  280  	}
195a4b4298a795 Il Han          2015-08-30  281  }
195a4b4298a795 Il Han          2015-08-30  282  
54187ff9d766b2 Guenter Roeck   2016-07-01  283  static int max31790_read_pwm(struct device *dev, u32 attr, int channel,
54187ff9d766b2 Guenter Roeck   2016-07-01  284  			     long *val)
195a4b4298a795 Il Han          2015-08-30  285  {
2c8602cfaeab63 Václav Kubernát 2021-03-16  286  	struct max31790_data *data = dev_get_drvdata(dev);
2c8602cfaeab63 Václav Kubernát 2021-03-16  287  	struct regmap *regmap = data->regmap;
2c8602cfaeab63 Václav Kubernát 2021-03-16  288  	int read;
195a4b4298a795 Il Han          2015-08-30  289  
195a4b4298a795 Il Han          2015-08-30  290  	if (IS_ERR(data))
195a4b4298a795 Il Han          2015-08-30  291  		return PTR_ERR(data);
195a4b4298a795 Il Han          2015-08-30  292  
54187ff9d766b2 Guenter Roeck   2016-07-01  293  	switch (attr) {
54187ff9d766b2 Guenter Roeck   2016-07-01  294  	case hwmon_pwm_input:
2c8602cfaeab63 Václav Kubernát 2021-03-16  295  		read = read_reg_word(regmap, MAX31790_REG_PWMOUT(channel));
2c8602cfaeab63 Václav Kubernát 2021-03-16  296  		if (read < 0)
2c8602cfaeab63 Václav Kubernát 2021-03-16  297  			return read;
2c8602cfaeab63 Václav Kubernát 2021-03-16  298  
2c8602cfaeab63 Václav Kubernát 2021-03-16  299  		*val = read >> 8;
54187ff9d766b2 Guenter Roeck   2016-07-01  300  		return 0;
54187ff9d766b2 Guenter Roeck   2016-07-01  301  	case hwmon_pwm_enable:
2c8602cfaeab63 Václav Kubernát 2021-03-16  302  		read = read_reg_byte(regmap, MAX31790_REG_FAN_CONFIG(channel));
2c8602cfaeab63 Václav Kubernát 2021-03-16  303  		if (read < 0)
2c8602cfaeab63 Václav Kubernát 2021-03-16  304  			return read;
2c8602cfaeab63 Václav Kubernát 2021-03-16  305  
2c8602cfaeab63 Václav Kubernát 2021-03-16  306  		if (read & MAX31790_FAN_CFG_RPM_MODE)
54187ff9d766b2 Guenter Roeck   2016-07-01  307  			*val = 2;
2c8602cfaeab63 Václav Kubernát 2021-03-16  308  		else if (read & MAX31790_FAN_CFG_TACH_INPUT_EN)
54187ff9d766b2 Guenter Roeck   2016-07-01  309  			*val = 1;
195a4b4298a795 Il Han          2015-08-30  310  		else
54187ff9d766b2 Guenter Roeck   2016-07-01  311  			*val = 0;
54187ff9d766b2 Guenter Roeck   2016-07-01  312  		return 0;
54187ff9d766b2 Guenter Roeck   2016-07-01  313  	default:
54187ff9d766b2 Guenter Roeck   2016-07-01  314  		return -EOPNOTSUPP;
54187ff9d766b2 Guenter Roeck   2016-07-01  315  	}
195a4b4298a795 Il Han          2015-08-30  316  }
195a4b4298a795 Il Han          2015-08-30  317  
54187ff9d766b2 Guenter Roeck   2016-07-01  318  static int max31790_write_pwm(struct device *dev, u32 attr, int channel,
54187ff9d766b2 Guenter Roeck   2016-07-01  319  			      long val)
195a4b4298a795 Il Han          2015-08-30  320  {
195a4b4298a795 Il Han          2015-08-30  321  	struct max31790_data *data = dev_get_drvdata(dev);
2c8602cfaeab63 Václav Kubernát 2021-03-16  322  	struct regmap *regmap = data->regmap;
54187ff9d766b2 Guenter Roeck   2016-07-01  323  	u8 fan_config;
54187ff9d766b2 Guenter Roeck   2016-07-01  324  	int err = 0;
195a4b4298a795 Il Han          2015-08-30  325  
54187ff9d766b2 Guenter Roeck   2016-07-01  326  	switch (attr) {
54187ff9d766b2 Guenter Roeck   2016-07-01  327  	case hwmon_pwm_input:
54187ff9d766b2 Guenter Roeck   2016-07-01  328  		if (val < 0 || val > 255) {
54187ff9d766b2 Guenter Roeck   2016-07-01  329  			err = -EINVAL;
54187ff9d766b2 Guenter Roeck   2016-07-01  330  			break;
54187ff9d766b2 Guenter Roeck   2016-07-01  331  		}
2c8602cfaeab63 Václav Kubernát 2021-03-16  332  		err = write_reg_word(regmap, MAX31790_REG_PWMOUT(channel), val << 8);
195a4b4298a795 Il Han          2015-08-30  333  		break;
54187ff9d766b2 Guenter Roeck   2016-07-01  334  	case hwmon_pwm_enable:
2c8602cfaeab63 Václav Kubernát 2021-03-16  335  		fan_config = read_reg_byte(regmap, MAX31790_REG_FAN_CONFIG(channel % NR_CHANNEL));
2c8602cfaeab63 Václav Kubernát 2021-03-16  336  
2c8602cfaeab63 Václav Kubernát 2021-03-16 @337  		if (fan_config < 0)
2c8602cfaeab63 Václav Kubernát 2021-03-16  338  			return fan_config;
2c8602cfaeab63 Václav Kubernát 2021-03-16  339  
54187ff9d766b2 Guenter Roeck   2016-07-01  340  		if (val == 0) {
54187ff9d766b2 Guenter Roeck   2016-07-01  341  			fan_config &= ~(MAX31790_FAN_CFG_TACH_INPUT_EN |
54187ff9d766b2 Guenter Roeck   2016-07-01  342  					MAX31790_FAN_CFG_RPM_MODE);
54187ff9d766b2 Guenter Roeck   2016-07-01  343  		} else if (val == 1) {
54187ff9d766b2 Guenter Roeck   2016-07-01  344  			fan_config = (fan_config |
54187ff9d766b2 Guenter Roeck   2016-07-01  345  				      MAX31790_FAN_CFG_TACH_INPUT_EN) &
54187ff9d766b2 Guenter Roeck   2016-07-01  346  				     ~MAX31790_FAN_CFG_RPM_MODE;
54187ff9d766b2 Guenter Roeck   2016-07-01  347  		} else if (val == 2) {
54187ff9d766b2 Guenter Roeck   2016-07-01  348  			fan_config |= MAX31790_FAN_CFG_TACH_INPUT_EN |
54187ff9d766b2 Guenter Roeck   2016-07-01  349  				      MAX31790_FAN_CFG_RPM_MODE;
54187ff9d766b2 Guenter Roeck   2016-07-01  350  		} else {
54187ff9d766b2 Guenter Roeck   2016-07-01  351  			err = -EINVAL;
195a4b4298a795 Il Han          2015-08-30  352  			break;
54187ff9d766b2 Guenter Roeck   2016-07-01  353  		}
2c8602cfaeab63 Václav Kubernát 2021-03-16  354  		err = regmap_write(regmap,
54187ff9d766b2 Guenter Roeck   2016-07-01  355  				   MAX31790_REG_FAN_CONFIG(channel),
54187ff9d766b2 Guenter Roeck   2016-07-01  356  				   fan_config);
195a4b4298a795 Il Han          2015-08-30  357  		break;
195a4b4298a795 Il Han          2015-08-30  358  	default:
54187ff9d766b2 Guenter Roeck   2016-07-01  359  		err = -EOPNOTSUPP;
54187ff9d766b2 Guenter Roeck   2016-07-01  360  		break;
195a4b4298a795 Il Han          2015-08-30  361  	}
195a4b4298a795 Il Han          2015-08-30  362  
195a4b4298a795 Il Han          2015-08-30  363  	return err;
195a4b4298a795 Il Han          2015-08-30  364  }
195a4b4298a795 Il Han          2015-08-30  365  
54187ff9d766b2 Guenter Roeck   2016-07-01  366  static umode_t max31790_pwm_is_visible(const void *_data, u32 attr, int channel)
195a4b4298a795 Il Han          2015-08-30  367  {
54187ff9d766b2 Guenter Roeck   2016-07-01  368  	const struct max31790_data *data = _data;
2c8602cfaeab63 Václav Kubernát 2021-03-16  369  	struct regmap *regmap = data->regmap;
2c8602cfaeab63 Václav Kubernát 2021-03-16  370  	u8 fan_config = read_reg_byte(regmap, MAX31790_REG_FAN_CONFIG(channel % NR_CHANNEL));
2c8602cfaeab63 Václav Kubernát 2021-03-16  371  
2c8602cfaeab63 Václav Kubernát 2021-03-16 @372  	if (fan_config < 0)
2c8602cfaeab63 Václav Kubernát 2021-03-16  373  		return 0;
54187ff9d766b2 Guenter Roeck   2016-07-01  374  
54187ff9d766b2 Guenter Roeck   2016-07-01  375  	switch (attr) {
54187ff9d766b2 Guenter Roeck   2016-07-01  376  	case hwmon_pwm_input:
54187ff9d766b2 Guenter Roeck   2016-07-01  377  	case hwmon_pwm_enable:
54187ff9d766b2 Guenter Roeck   2016-07-01  378  		if (!(fan_config & MAX31790_FAN_CFG_TACH_INPUT))
dc8dbb4d7672b7 Guenter Roeck   2018-12-10  379  			return 0644;
54187ff9d766b2 Guenter Roeck   2016-07-01  380  		return 0;
54187ff9d766b2 Guenter Roeck   2016-07-01  381  	default:
54187ff9d766b2 Guenter Roeck   2016-07-01  382  		return 0;
54187ff9d766b2 Guenter Roeck   2016-07-01  383  	}
54187ff9d766b2 Guenter Roeck   2016-07-01  384  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 31803 bytes --]

  parent reply	other threads:[~2021-03-17  5:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 17:54 [PATCH v2 1/5] hwmon: (max31790) Rework to use regmap Václav Kubernát
2021-03-16 17:54 ` [PATCH v2 2/5] hwmon: (max31790) Fix and split pwm*_enable Václav Kubernát
2021-03-16 17:55 ` [PATCH v2 3/5] hwmon: (max31790) Show 0 RPM/fault when input disabled Václav Kubernát
2021-03-16 17:55 ` [PATCH v2 4/5] hwmon: (max31790) Allow setting fan*_div Václav Kubernát
2021-03-16 17:55 ` [PATCH v2 5/5] hwmon: (max31790) Update documentation Václav Kubernát
2021-03-16 18:11 ` [PATCH v2 1/5] hwmon: (max31790) Rework to use regmap Václav Kubernát
2021-03-17  5:12 ` Dan Carpenter [this message]
2021-03-18  9:56   ` Václav Kubernát
     [not found] ` <20210329222704.GA223476@roeck-us.net>
2021-03-30  3:43   ` Václav Kubernát
2021-04-13  2:59 Václav Kubernát
2021-04-13  3:10 ` Václav Kubernát
2021-04-22  1:27 ` Guenter Roeck
2021-04-23 10:55   ` Václav Kubernát
2021-04-26 12:46   ` Václav Kubernát
2021-04-26 14:17     ` Guenter Roeck
2021-04-26 14:29       ` Václav Kubernát
2021-04-26 14:35         ` Guenter Roeck

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=20210317051239.GW2087@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=corbet@lwn.net \
    --cc=jdelvare@suse.com \
    --cc=kbuild-all@lists.01.org \
    --cc=kbuild@lists.01.org \
    --cc=kubernat@cesnet.cz \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lkp@intel.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;
as well as URLs for NNTP newsgroup(s).