Merge tag 'w1-drv-6.5' of https://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux...
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 1 Jun 2023 17:53:51 +0000 (18:53 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 1 Jun 2023 17:53:51 +0000 (18:53 +0100)
Krzysztof writes:

1-Wire bus drivers for v6.5

1. Several older cleanups and minor improvements like dropping redundant
   match function, fixing indentation and typos, simplifying sysfs
   attribute show, removing redundant variable initializations, using max()
   instead of open-coding it and constifying pointer to
   struct hwmon_channel_info.

2. w1_therm: fix inverted lock handling causing spurious temperature
   reads.

3. sgi: Use strscpy() over strlcpy().

4. w1 bus fixes:
   - Correct missing OF node reference put in error path.
   - Correct iterating over master device list while removing items from
     it.
   - Don't use loop iterator past the loop.

* tag 'w1-drv-6.5' of https://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux-w1:
  w1: Replace usage of found with dedicated list iterator variable
  w1: therm: constify pointers to hwmon_channel_info
  w1: Add missing of_node_put() in w1.c
  w1: no need to initialise statics to 0
  w1: ds2438: remove redundant initialization of variable crc
  w1: w1_therm: fix typo in comment
  w1: w1_therm: Use max() instead of doing it manually
  w1: fix loop in w1_fini()
  w1: remove redundant initialization to variable result
  w1: Simplify the atribute show
  w1: Fix Kconfig indentation
  w1: sgi: move from strlcpy with unused retval to strscpy
  w1: Remove driver match function
  w1: w1_therm: fix locking behavior in convert_t

drivers/w1/masters/sgi_w1.c
drivers/w1/slaves/Kconfig
drivers/w1/slaves/w1_ds2438.c
drivers/w1/slaves/w1_therm.c
drivers/w1/w1.c

index e8c7fa6..d7fbc3c 100644 (file)
@@ -93,7 +93,7 @@ static int sgi_w1_probe(struct platform_device *pdev)
 
        pdata = dev_get_platdata(&pdev->dev);
        if (pdata) {
-               strlcpy(sdev->dev_id, pdata->dev_id, sizeof(sdev->dev_id));
+               strscpy(sdev->dev_id, pdata->dev_id, sizeof(sdev->dev_id));
                sdev->bus_master.dev_id = sdev->dev_id;
        }
 
index 6877538..32b8a75 100644 (file)
@@ -71,8 +71,8 @@ config W1_SLAVE_DS2805
        help
          Say Y here if you want to use a 1-wire
          is a 112-byte user-programmable EEPROM is
-          organized as 7 pages of 16 bytes each with 64bit
-          unique number. Requires OverDrive Speed to talk to.
+         organized as 7 pages of 16 bytes each with 64bit
+         unique number. Requires OverDrive Speed to talk to.
 
 config W1_SLAVE_DS2430
        tristate "256b EEPROM family support (DS2430)"
index ca64f99..e008c27 100644 (file)
@@ -66,8 +66,6 @@ static int w1_ds2438_get_page(struct w1_slave *sl, int pageno, u8 *buf)
        size_t count;
 
        while (retries--) {
-               crc = 0;
-
                if (w1_reset_select_slave(sl))
                        continue;
                w1_buf[0] = W1_DS2438_RECALL_MEMORY;
index 0676926..c85e80c 100644 (file)
@@ -284,7 +284,7 @@ static int read_powermode(struct w1_slave *sl);
  * trigger_bulk_read() - function to trigger a bulk read on the bus
  * @dev_master: the device master of the bus
  *
- * Send a SKIP ROM follow by a CONVERT T commmand on the bus.
+ * Send a SKIP ROM follow by a CONVERT T command on the bus.
  * It also set the status flag in each slave &struct w1_therm_family_data
  * to signal that a conversion is in progress.
  *
@@ -454,7 +454,7 @@ static const struct hwmon_channel_info w1_temp = {
        .config = w1_temp_config,
 };
 
-static const struct hwmon_channel_info *w1_info[] = {
+static const struct hwmon_channel_info * const w1_info[] = {
        &w1_temp,
        NULL
 };
@@ -1159,29 +1159,26 @@ static int convert_t(struct w1_slave *sl, struct therm_info *info)
 
                        w1_write_8(dev_master, W1_CONVERT_TEMP);
 
-                       if (strong_pullup) { /*some device need pullup */
+                       if (SLAVE_FEATURES(sl) & W1_THERM_POLL_COMPLETION) {
+                               ret = w1_poll_completion(dev_master, W1_POLL_CONVERT_TEMP);
+                               if (ret) {
+                                       dev_dbg(&sl->dev, "%s: Timeout\n", __func__);
+                                       goto mt_unlock;
+                               }
+                               mutex_unlock(&dev_master->bus_mutex);
+                       } else if (!strong_pullup) { /*no device need pullup */
                                sleep_rem = msleep_interruptible(t_conv);
                                if (sleep_rem != 0) {
                                        ret = -EINTR;
                                        goto mt_unlock;
                                }
                                mutex_unlock(&dev_master->bus_mutex);
-                       } else { /*no device need pullup */
-                               if (SLAVE_FEATURES(sl) & W1_THERM_POLL_COMPLETION) {
-                                       ret = w1_poll_completion(dev_master, W1_POLL_CONVERT_TEMP);
-                                       if (ret) {
-                                               dev_dbg(&sl->dev, "%s: Timeout\n", __func__);
-                                               goto mt_unlock;
-                                       }
-                                       mutex_unlock(&dev_master->bus_mutex);
-                               } else {
-                                       /* Fixed delay */
-                                       mutex_unlock(&dev_master->bus_mutex);
-                                       sleep_rem = msleep_interruptible(t_conv);
-                                       if (sleep_rem != 0) {
-                                               ret = -EINTR;
-                                               goto dec_refcnt;
-                                       }
+                       } else { /*some device need pullup */
+                               mutex_unlock(&dev_master->bus_mutex);
+                               sleep_rem = msleep_interruptible(t_conv);
+                               if (sleep_rem != 0) {
+                                       ret = -EINTR;
+                                       goto dec_refcnt;
                                }
                        }
                        ret = read_scratchpad(sl, info);
@@ -1515,7 +1512,7 @@ static int trigger_bulk_read(struct w1_master *dev_master)
                if (bulk_read_support(sl)) {
                        int t_cur = conversion_time(sl);
 
-                       t_conv = t_cur > t_conv ? t_cur : t_conv;
+                       t_conv = max(t_cur, t_conv);
                        strong_pullup = strong_pullup ||
                                        (w1_strong_pullup == 2 ||
                                        (!SLAVE_POWERMODE(sl) &&
index 9d199fe..5353cbd 100644 (file)
@@ -32,7 +32,7 @@ static int w1_timeout = 10;
 module_param_named(timeout, w1_timeout, int, 0);
 MODULE_PARM_DESC(timeout, "time in seconds between automatic slave searches");
 
-static int w1_timeout_us = 0;
+static int w1_timeout_us;
 module_param_named(timeout_us, w1_timeout_us, int, 0);
 MODULE_PARM_DESC(timeout_us,
                 "time in microseconds between automatic slave searches");
@@ -58,11 +58,6 @@ MODULE_PARM_DESC(slave_ttl,
 DEFINE_MUTEX(w1_mlock);
 LIST_HEAD(w1_masters);
 
-static int w1_master_match(struct device *dev, struct device_driver *drv)
-{
-       return 1;
-}
-
 static int w1_master_probe(struct device *dev)
 {
        return -ENODEV;
@@ -174,7 +169,6 @@ static int w1_uevent(const struct device *dev, struct kobj_uevent_env *env);
 
 static struct bus_type w1_bus_type = {
        .name = "w1",
-       .match = w1_master_match,
        .uevent = w1_uevent,
 };
 
@@ -301,17 +295,13 @@ static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct devic
 
 static ssize_t w1_master_attribute_show_timeout(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       ssize_t count;
-       count = sprintf(buf, "%d\n", w1_timeout);
-       return count;
+       return sprintf(buf, "%d\n", w1_timeout);
 }
 
 static ssize_t w1_master_attribute_show_timeout_us(struct device *dev,
        struct device_attribute *attr, char *buf)
 {
-       ssize_t count;
-       count = sprintf(buf, "%d\n", w1_timeout_us);
-       return count;
+       return sprintf(buf, "%d\n", w1_timeout_us);
 }
 
 static ssize_t w1_master_attribute_store_max_slave_count(struct device *dev,
@@ -501,7 +491,7 @@ static ssize_t w1_master_attribute_store_remove(struct device *dev,
        struct w1_master *md = dev_to_w1_master(dev);
        struct w1_reg_num rn;
        struct w1_slave *sl;
-       ssize_t result = count;
+       ssize_t result;
 
        if (w1_atoreg_num(dev, buf, count, &rn))
                return -EINVAL;
@@ -702,6 +692,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
                dev_err(&sl->dev,
                        "Device registration [%s] failed. err=%d\n",
                        dev_name(&sl->dev), err);
+               of_node_put(sl->dev.of_node);
                put_device(&sl->dev);
                return err;
        }
@@ -830,49 +821,47 @@ int w1_slave_detach(struct w1_slave *sl)
 
 struct w1_master *w1_search_master_id(u32 id)
 {
-       struct w1_master *dev;
-       int found = 0;
+       struct w1_master *dev = NULL, *iter;
 
        mutex_lock(&w1_mlock);
-       list_for_each_entry(dev, &w1_masters, w1_master_entry) {
-               if (dev->id == id) {
-                       found = 1;
-                       atomic_inc(&dev->refcnt);
+       list_for_each_entry(iter, &w1_masters, w1_master_entry) {
+               if (iter->id == id) {
+                       dev = iter;
+                       atomic_inc(&iter->refcnt);
                        break;
                }
        }
        mutex_unlock(&w1_mlock);
 
-       return (found)?dev:NULL;
+       return dev;
 }
 
 struct w1_slave *w1_search_slave(struct w1_reg_num *id)
 {
        struct w1_master *dev;
-       struct w1_slave *sl = NULL;
-       int found = 0;
+       struct w1_slave *sl = NULL, *iter;
 
        mutex_lock(&w1_mlock);
        list_for_each_entry(dev, &w1_masters, w1_master_entry) {
                mutex_lock(&dev->list_mutex);
-               list_for_each_entry(sl, &dev->slist, w1_slave_entry) {
-                       if (sl->reg_num.family == id->family &&
-                                       sl->reg_num.id == id->id &&
-                                       sl->reg_num.crc == id->crc) {
-                               found = 1;
+               list_for_each_entry(iter, &dev->slist, w1_slave_entry) {
+                       if (iter->reg_num.family == id->family &&
+                           iter->reg_num.id == id->id &&
+                           iter->reg_num.crc == id->crc) {
+                               sl = iter;
                                atomic_inc(&dev->refcnt);
-                               atomic_inc(&sl->refcnt);
+                               atomic_inc(&iter->refcnt);
                                break;
                        }
                }
                mutex_unlock(&dev->list_mutex);
 
-               if (found)
+               if (sl)
                        break;
        }
        mutex_unlock(&w1_mlock);
 
-       return (found)?sl:NULL;
+       return sl;
 }
 
 void w1_reconnect_slaves(struct w1_family *f, int attach)
@@ -1263,10 +1252,10 @@ err_out_exit_init:
 
 static void __exit w1_fini(void)
 {
-       struct w1_master *dev;
+       struct w1_master *dev, *n;
 
        /* Set netlink removal messages and some cleanup */
-       list_for_each_entry(dev, &w1_masters, w1_master_entry)
+       list_for_each_entry_safe(dev, n, &w1_masters, w1_master_entry)
                __w1_remove_master_device(dev);
 
        w1_fini_netlink();