mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] w1: w1_therm: fix missing therm_bulk_read sysfs attribute with multiple bus masters
@ 2026-09-27 10:43 lorenzo.castellani
  2026-09-30  5:23 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 5+ messages in thread
From: lorenzo.castellani @ 2026-09-27 10:43 UTC (permalink / raw)
  To: krzk; +Cc: linux-kernel

 From 32e145b49cf41ce150a97ce52c63f5aae1bbbea7 Mon Sep 17 00:00:00 2001
From: Lorenzo Castellani <lorenzo.castellani@pd.infn.it>
Date: Tue, 22 Sep 2026 11:12:30 +0200
Subject: [PATCH] w1: w1_therm: fix missing therm_bulk_read sysfs attribute
  with multiple bus masters

When multiple 1-Wire bus masters are present in the
system, the global module-level counter causes the
therm_bulk_read sysfs attribute to be created only
for the first master where a bulk-read capable slave
is discovered. Subsequent bus masters fail to expose
the attribute because the counter is already non-zero.

Fix this by replacing the global static counter with
a per-master helper function that iterates over the
slaves associated specifically with the given master
(dev_master->slist). This ensures that each bus
master independently correctly tracks and exposes the
therm_bulk_read sysfs attribute when bulk-read
capable devices are present.

Signed-off-by: Lorenzo Castellani <lorenzo.castellani@pd.infn.it>
---
  linux-rpi-6.18.y/drivers/w1/slaves/w1_therm.c | 30 ++++++++++++-------
  1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/linux-rpi-6.18.y/drivers/w1/slaves/w1_therm.c 
b/linux-rpi-6.18.y/drivers/w1/slaves/w1_therm.c
index 832e3da94..4c8e67ec8 100644
--- a/linux-rpi-6.18.y/drivers/w1/slaves/w1_therm.c
+++ b/linux-rpi-6.18.y/drivers/w1/slaves/w1_therm.c
@@ -44,9 +44,6 @@
  static int w1_strong_pullup = 1;
  module_param_named(strong_pullup, w1_strong_pullup, int, 0);

-/* Counter for devices supporting bulk reading */
-static u16 bulk_read_device_counter; /* =0 as per C standard */
-
  /* This command should be in public header w1.h but is not */
  #define W1_RECALL_EEPROM    0xB8

@@ -968,6 +965,19 @@ static inline s8 int_to_short(int i)

  /* Interface Functions */

+static int w1_therm_count_bulk_read_slaves(struct w1_master *dev_master,
+    struct w1_slave *exclude_sl)
+{
+    struct w1_slave *sl;
+    int count = 0;
+
+    list_for_each_entry(sl, &dev_master->slist, w1_slave_entry) {
+        if (sl != exclude_sl && sl->family_data && bulk_read_support(sl))
+            count++;
+    }
+    return count;
+}
+
  static int w1_therm_add_slave(struct w1_slave *sl)
  {
      struct w1_therm_family_converter *sl_family_conv;
@@ -992,9 +1002,11 @@ static int w1_therm_add_slave(struct w1_slave *sl)
      if (bulk_read_support(sl)) {
          /*
           * add the sys entry to trigger bulk_read
-         * at master level only the 1st time
+         * at master level only the 1st time on this master
           */
-        if (!bulk_read_device_counter) {
+        int bulk_count = w1_therm_count_bulk_read_slaves(sl->master, sl);
+
+        if (!bulk_count) {
              int err = device_create_file(&sl->master->dev,
                  &dev_attr_therm_bulk_read);

@@ -1003,8 +1015,6 @@ static int w1_therm_add_slave(struct w1_slave *sl)
                  "%s: Device has been added, but bulk read is 
unavailable. err=%d\n",
                  __func__, err);
          }
-        /* Increment the counter */
-        bulk_read_device_counter++;
      }

      /* Getting the power mode of the device {external, parasite} */
@@ -1040,9 +1050,9 @@ static void w1_therm_remove_slave(struct w1_slave *sl)
      int refcnt = atomic_sub_return(1, THERM_REFCNT(sl->family_data));

      if (bulk_read_support(sl)) {
-        bulk_read_device_counter--;
-        /* Delete the entry if no more device support the feature */
-        if (!bulk_read_device_counter)
+        int bulk_count = w1_therm_count_bulk_read_slaves(sl->master, sl);
+        /* Delete the entry if no more device support the feature on 
this master */
+        if (!bulk_count)
              device_remove_file(&sl->master->dev,
                  &dev_attr_therm_bulk_read);
      }
-- 
2.43.0



^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH] w1: w1_therm: fix missing therm_bulk_read sysfs attribute with multiple bus masters
@ 2026-09-27  9:59 Lorenzo Castellani
  0 siblings, 0 replies; 5+ messages in thread
From: Lorenzo Castellani @ 2026-09-27  9:59 UTC (permalink / raw)
  To: w1; +Cc: linux-kernel

 From 32e145b49cf41ce150a97ce52c63f5aae1bbbea7 Mon Sep 17 00:00:00 2001
From: Lorenzo Castellani <lorenzo.castellani@pd.infn.it>
Date: Tue, 22 Sep 2026 11:12:30 +0200
Subject: [PATCH] w1: w1_therm: fix missing therm_bulk_read sysfs attribute
  with multiple bus masters

When multiple 1-Wire bus masters are present in the
system, the global module-level counter causes the
therm_bulk_read sysfs attribute to be created only
for the first master where a bulk-read capable slave
is discovered. Subsequent bus masters fail to expose
the attribute because the counter is already non-zero.

Fix this by replacing the global static counter with
a per-master helper function that iterates over the
slaves associated specifically with the given master
(dev_master->slist). This ensures that each bus
master independently correctly tracks and exposes the
therm_bulk_read sysfs attribute when bulk-read
capable devices are present.

Signed-off-by: Lorenzo Castellani <lorenzo.castellani@pd.infn.it>
---
  linux-rpi-6.18.y/drivers/w1/slaves/w1_therm.c | 30 ++++++++++++-------
  1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/linux-rpi-6.18.y/drivers/w1/slaves/w1_therm.c 
b/linux-rpi-6.18.y/drivers/w1/slaves/w1_therm.c
index 832e3da94..4c8e67ec8 100644
--- a/linux-rpi-6.18.y/drivers/w1/slaves/w1_therm.c
+++ b/linux-rpi-6.18.y/drivers/w1/slaves/w1_therm.c
@@ -44,9 +44,6 @@
  static int w1_strong_pullup = 1;
  module_param_named(strong_pullup, w1_strong_pullup, int, 0);

-/* Counter for devices supporting bulk reading */
-static u16 bulk_read_device_counter; /* =0 as per C standard */
-
  /* This command should be in public header w1.h but is not */
  #define W1_RECALL_EEPROM    0xB8

@@ -968,6 +965,19 @@ static inline s8 int_to_short(int i)

  /* Interface Functions */

+static int w1_therm_count_bulk_read_slaves(struct w1_master *dev_master,
+    struct w1_slave *exclude_sl)
+{
+    struct w1_slave *sl;
+    int count = 0;
+
+    list_for_each_entry(sl, &dev_master->slist, w1_slave_entry) {
+        if (sl != exclude_sl && sl->family_data && bulk_read_support(sl))
+            count++;
+    }
+    return count;
+}
+
  static int w1_therm_add_slave(struct w1_slave *sl)
  {
      struct w1_therm_family_converter *sl_family_conv;
@@ -992,9 +1002,11 @@ static int w1_therm_add_slave(struct w1_slave *sl)
      if (bulk_read_support(sl)) {
          /*
           * add the sys entry to trigger bulk_read
-         * at master level only the 1st time
+         * at master level only the 1st time on this master
           */
-        if (!bulk_read_device_counter) {
+        int bulk_count = w1_therm_count_bulk_read_slaves(sl->master, sl);
+
+        if (!bulk_count) {
              int err = device_create_file(&sl->master->dev,
                  &dev_attr_therm_bulk_read);

@@ -1003,8 +1015,6 @@ static int w1_therm_add_slave(struct w1_slave *sl)
                  "%s: Device has been added, but bulk read is 
unavailable. err=%d\n",
                  __func__, err);
          }
-        /* Increment the counter */
-        bulk_read_device_counter++;
      }

      /* Getting the power mode of the device {external, parasite} */
@@ -1040,9 +1050,9 @@ static void w1_therm_remove_slave(struct w1_slave *sl)
      int refcnt = atomic_sub_return(1, THERM_REFCNT(sl->family_data));

      if (bulk_read_support(sl)) {
-        bulk_read_device_counter--;
-        /* Delete the entry if no more device support the feature */
-        if (!bulk_read_device_counter)
+        int bulk_count = w1_therm_count_bulk_read_slaves(sl->master, sl);
+        /* Delete the entry if no more device support the feature on 
this master */
+        if (!bulk_count)
              device_remove_file(&sl->master->dev,
                  &dev_attr_therm_bulk_read);
      }
-- 
2.43.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-30  8:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-27 10:43 [PATCH] w1: w1_therm: fix missing therm_bulk_read sysfs attribute with multiple bus masters lorenzo.castellani
2026-09-30  5:23 ` Krzysztof Kozlowski
2026-09-30  6:01   ` Lorenzo Castellani
2026-09-30  8:41     ` Krzysztof Kozlowski
  -- strict thread matches above, loose matches on Subject: below --
2026-09-27  9:59 Lorenzo Castellani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®