Skip to contentSkip to conversation

hwmon: (nct6775) Regression Bisected

PATCH Doug Smythies 5 participants 15 messages Sep 15, 2023 – Sep 21, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Kernel 6.6-rc1 has an error during boot. The guilty commit is:
b7f1f7b2523a6a4382f12fe953380b847b80e09d
hwmon: (nct6775) Additional TEMP registers for nct6799

There seems to be confusion between the indexes into the NCT6799_ALARM_BITS array or the NCT6779_ALARM_BITS array. I do not understand the code and do not know if it is the indexing that is reversed or the wrong table is being used.

The error from kern.log (edited):

================================================================================

UBSAN: shift-out-of-bounds in drivers/hwmon/nct6775-core.c:1757:39
shift exponent -1 is negative
CPU: 9 PID: 822 Comm: sensors Not tainted 6.6.0-rc1-stock2 #1165
Hardware name: ASUS System Product Name/PRIME Z490-A, BIOS 9902 09/15/2021
Call Trace:
<TASK>
dump_stack_lvl+0x48/0x70
dump_stack+0x10/0x20
ubsan_epilogue+0x9/0x40
__ubsan_handle_shift_out_of_bounds+0x10f/0x170

...

I added a "pr_info" line (in the below it was as of the prior commit, 43fbe66dc216 hwmon: Add driver for Renesas HS3001):

doug@s19:~/kernel/linux$ git diff
drivers/hwmon/nct6775-core.c +1 -0
index 33533d95cf48..12e3df84c034 100644
@@ -1727,6 +1727,7 @@ nct6775_show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
                return PTR_ERR(data);
 
        nr = data->ALARM_BITS[sattr->index];
+       pr_info("doug: nr: %d  ; index %d\n", nr, sattr->index);
        return sprintf(buf, "%u\n",
                       (unsigned int)((data->alarms >> nr) & 0x01));
 }

And for b7f1f7b2523a got (edited):

nct6775_core: doug: nr: 0 ; index 0
nct6775_core: doug: nr: 1 ; index 1
nct6775_core: doug: nr: 2 ; index 2
nct6775_core: doug: nr: 3 ; index 3
nct6775_core: doug: nr: 8 ; index 4
nct6775_core: doug: nr: -1 ; index 5
================================================================================

UBSAN: shift-out-of-bounds in drivers/hwmon/nct6775-core.c:1758:39

shift exponent -1 is negative
...
nct6775_core: doug: nr: 20 ; index 6
nct6775_core: doug: nr: 16 ; index 7
nct6775_core: doug: nr: 17 ; index 8
nct6775_core: doug: nr: 24 ; index 9
nct6775_core: doug: nr: 25 ; index 10
nct6775_core: doug: nr: 26 ; index 11
nct6775_core: doug: nr: 27 ; index 12
nct6775_core: doug: nr: 28 ; index 13
nct6775_core: doug: nr: 29 ; index 14
nct6775_core: doug: nr: 6 ; index 24
nct6775_core: doug: nr: 7 ; index 25
nct6775_core: doug: nr: 11 ; index 26
nct6775_core: doug: nr: 10 ; index 27
nct6775_core: doug: nr: 23 ; index 28
nct6775_core: doug: nr: 33 ; index 29
nct6775_core: doug: nr: 12 ; index 48
nct6775_core: doug: nr: 9 ; index 49

Observe that the table seems to be
NCT6799_ALARM_BITS
But the indexes seem to be for
NCT6779_ALARM_BITS

static const s8 NCT6799_ALARM_BITS[NUM_ALARM_BITS] = {
         0,  1,  2,  3,  8, -1, 20, 16, 17, 24, 25, 26,   /* in0-in11     */
        27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1,   /* in12-in23    */
         6,  7, 11, 10, 23, 33, -1, -1, -1, -1, -1, -1,   /* fan1-fan12   */
         4,  5, 40, 41, 42, 43, 44, -1, -1, -1, -1, -1,   /* temp1-temp12 */
        12,  9,                                           /* intr0-intr1  */
};

Now repeat the test as of 43fbe66dc216:

nct6775_core: doug: nr: 0 ; index 0
nct6775_core: doug: nr: 1 ; index 1
nct6775_core: doug: nr: 2 ; index 2
nct6775_core: doug: nr: 3 ; index 3
nct6775_core: doug: nr: 8 ; index 4
nct6775_core: doug: nr: 21 ; index 5
nct6775_core: doug: nr: 20 ; index 6
nct6775_core: doug: nr: 16 ; index 7
nct6775_core: doug: nr: 17 ; index 8
nct6775_core: doug: nr: 24 ; index 9
nct6775_core: doug: nr: 25 ; index 10
nct6775_core: doug: nr: 26 ; index 11
nct6775_core: doug: nr: 27 ; index 12
nct6775_core: doug: nr: 28 ; index 13
nct6775_core: doug: nr: 29 ; index 14
nct6775_core: doug: nr: 6 ; index 24
nct6775_core: doug: nr: 7 ; index 25
nct6775_core: doug: nr: 11 ; index 26
nct6775_core: doug: nr: 10 ; index 27
nct6775_core: doug: nr: 23 ; index 28
nct6775_core: doug: nr: 33 ; index 29
nct6775_core: doug: nr: 12 ; index 48
nct6775_core: doug: nr: 9 ; index 49

Observe that the table seems to be
NCT6779_ALARM_BITS
And the indexing seems to be for that
Table.

static const s8 NCT6779_ALARM_BITS[NUM_ALARM_BITS] = {
         0,  1,  2,  3,  8, 21, 20, 16, 17, 24, 25, 26,   /* in0-in11     */
        27, 28, 29, -1, -1, -1, -1, -1, -1, -1, -1, -1,   /* in12-in23    */
         6,  7, 11, 10, 23, -1, -1, -1, -1, -1, -1, -1,   /* fan1-fan12   */
         4,  5, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1,   /* temp1-temp12 */
        12,  9,                                           /* intr0-intr1  */
};

You probably need this information:
nct6775: Found NCT6798D or compatible chip at 0x2e:0x290

... Doug

maintainer
#1 lore raw

Hi,

Quoted 10 lines · Doug Smythies

Kernel 6.6-rc1 has an error during boot. The guilty commit is:
b7f1f7b2523a6a4382f12fe953380b847b80e09d
hwmon: (nct6775) Additional TEMP registers for nct6799

There seems to be confusion between the indexes into the NCT6799_ALARM_BITS array or the NCT6779_ALARM_BITS array. I do not understand the code and do not know if it is the indexing that is reversed or the wrong table is being used.

Thanks a lot for the report. Ahmad, can you look into this ? If it can't be fixed quickly we'll have to revert the offending patch.

Thanks,
Guenter

Quoted 120 lines

The error from kern.log (edited):

================================================================================

UBSAN: shift-out-of-bounds in drivers/hwmon/nct6775-core.c:1757:39
shift exponent -1 is negative
CPU: 9 PID: 822 Comm: sensors Not tainted 6.6.0-rc1-stock2 #1165
Hardware name: ASUS System Product Name/PRIME Z490-A, BIOS 9902 09/15/2021
Call Trace:
<TASK>
dump_stack_lvl+0x48/0x70
dump_stack+0x10/0x20
ubsan_epilogue+0x9/0x40
__ubsan_handle_shift_out_of_bounds+0x10f/0x170

...

I added a "pr_info" line (in the below it was as of the prior commit, 43fbe66dc216 hwmon: Add driver for Renesas HS3001):

doug@s19:~/kernel/linux$ git diff
drivers/hwmon/nct6775-core.c +1 -0
index 33533d95cf48..12e3df84c034 100644
@@ -1727,6 +1727,7 @@ nct6775_show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
                 return PTR_ERR(data);
 
         nr = data->ALARM_BITS[sattr->index];
+       pr_info("doug: nr: %d  ; index %d\n", nr, sattr->index);
         return sprintf(buf, "%u\n",
                        (unsigned int)((data->alarms >> nr) & 0x01));
  }

And for b7f1f7b2523a got (edited):

nct6775_core: doug: nr: 0 ; index 0
nct6775_core: doug: nr: 1 ; index 1
nct6775_core: doug: nr: 2 ; index 2
nct6775_core: doug: nr: 3 ; index 3
nct6775_core: doug: nr: 8 ; index 4
nct6775_core: doug: nr: -1 ; index 5
================================================================================

UBSAN: shift-out-of-bounds in drivers/hwmon/nct6775-core.c:1758:39

shift exponent -1 is negative
...
nct6775_core: doug: nr: 20 ; index 6
nct6775_core: doug: nr: 16 ; index 7
nct6775_core: doug: nr: 17 ; index 8
nct6775_core: doug: nr: 24 ; index 9
nct6775_core: doug: nr: 25 ; index 10
nct6775_core: doug: nr: 26 ; index 11
nct6775_core: doug: nr: 27 ; index 12
nct6775_core: doug: nr: 28 ; index 13
nct6775_core: doug: nr: 29 ; index 14
nct6775_core: doug: nr: 6 ; index 24
nct6775_core: doug: nr: 7 ; index 25
nct6775_core: doug: nr: 11 ; index 26
nct6775_core: doug: nr: 10 ; index 27
nct6775_core: doug: nr: 23 ; index 28
nct6775_core: doug: nr: 33 ; index 29
nct6775_core: doug: nr: 12 ; index 48
nct6775_core: doug: nr: 9 ; index 49

Observe that the table seems to be
NCT6799_ALARM_BITS
But the indexes seem to be for
NCT6779_ALARM_BITS

static const s8 NCT6799_ALARM_BITS[NUM_ALARM_BITS] = {
          0,  1,  2,  3,  8, -1, 20, 16, 17, 24, 25, 26,   /* in0-in11     */
         27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1,   /* in12-in23    */
          6,  7, 11, 10, 23, 33, -1, -1, -1, -1, -1, -1,   /* fan1-fan12   */
          4,  5, 40, 41, 42, 43, 44, -1, -1, -1, -1, -1,   /* temp1-temp12 */
         12,  9,                                           /* intr0-intr1  */
};

Now repeat the test as of 43fbe66dc216:

nct6775_core: doug: nr: 0 ; index 0
nct6775_core: doug: nr: 1 ; index 1
nct6775_core: doug: nr: 2 ; index 2
nct6775_core: doug: nr: 3 ; index 3
nct6775_core: doug: nr: 8 ; index 4
nct6775_core: doug: nr: 21 ; index 5
nct6775_core: doug: nr: 20 ; index 6
nct6775_core: doug: nr: 16 ; index 7
nct6775_core: doug: nr: 17 ; index 8
nct6775_core: doug: nr: 24 ; index 9
nct6775_core: doug: nr: 25 ; index 10
nct6775_core: doug: nr: 26 ; index 11
nct6775_core: doug: nr: 27 ; index 12
nct6775_core: doug: nr: 28 ; index 13
nct6775_core: doug: nr: 29 ; index 14
nct6775_core: doug: nr: 6 ; index 24
nct6775_core: doug: nr: 7 ; index 25
nct6775_core: doug: nr: 11 ; index 26
nct6775_core: doug: nr: 10 ; index 27
nct6775_core: doug: nr: 23 ; index 28
nct6775_core: doug: nr: 33 ; index 29
nct6775_core: doug: nr: 12 ; index 48
nct6775_core: doug: nr: 9 ; index 49

Observe that the table seems to be
NCT6779_ALARM_BITS
And the indexing seems to be for that
Table.

static const s8 NCT6779_ALARM_BITS[NUM_ALARM_BITS] = {
          0,  1,  2,  3,  8, 21, 20, 16, 17, 24, 25, 26,   /* in0-in11     */
         27, 28, 29, -1, -1, -1, -1, -1, -1, -1, -1, -1,   /* in12-in23    */
          6,  7, 11, 10, 23, -1, -1, -1, -1, -1, -1, -1,   /* fan1-fan12   */
          4,  5, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1,   /* temp1-temp12 */
         12,  9,                                           /* intr0-intr1  */
};

You probably need this information:
nct6775: Found NCT6798D or compatible chip at 0x2e:0x290

... Doug

maintainer
#2 lore raw
Quoted 14 lines · Guenter Roeck

Hi,

Quoted 10 lines · Doug Smythies

Kernel 6.6-rc1 has an error during boot. The guilty commit is:
b7f1f7b2523a6a4382f12fe953380b847b80e09d
hwmon: (nct6775) Additional TEMP registers for nct6799

There seems to be confusion between the indexes into the NCT6799_ALARM_BITS array or the NCT6779_ALARM_BITS array. I do not understand the code and do not know if it is the indexing that is reversed or the wrong table is being used.

Quoted 3 lines

Thanks a lot for the report. Ahmad, can you look into this ? If it can't be fixed quickly we'll have to revert the offending patch.

I'll wait until around mid next week and then revert the offending patch if we don't have a solution by then.

Sorry for the trouble.

Thanks,
Guenter

#13 lore raw
In reply to Doug Smythies
Quoted 124 lines · Doug Smythies

Kernel 6.6-rc1 has an error during boot. The guilty commit is:
b7f1f7b2523a6a4382f12fe953380b847b80e09d
hwmon: (nct6775) Additional TEMP registers for nct6799

There seems to be confusion between the indexes into the NCT6799_ALARM_BITS array or the NCT6779_ALARM_BITS array. I do not understand the code and do not know if it is the indexing that is reversed or the wrong table is being used.

The error from kern.log (edited):

================================================================================

UBSAN: shift-out-of-bounds in drivers/hwmon/nct6775-core.c:1757:39
shift exponent -1 is negative
CPU: 9 PID: 822 Comm: sensors Not tainted 6.6.0-rc1-stock2 #1165
Hardware name: ASUS System Product Name/PRIME Z490-A, BIOS 9902 09/15/2021
Call Trace:
<TASK>
dump_stack_lvl+0x48/0x70
dump_stack+0x10/0x20
ubsan_epilogue+0x9/0x40
__ubsan_handle_shift_out_of_bounds+0x10f/0x170

...

I added a "pr_info" line (in the below it was as of the prior commit, 43fbe66dc216 hwmon: Add driver for Renesas HS3001):

doug@s19:~/kernel/linux$ git diff
drivers/hwmon/nct6775-core.c +1 -0
index 33533d95cf48..12e3df84c034 100644
@@ -1727,6 +1727,7 @@ nct6775_show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
                return PTR_ERR(data);
 
        nr = data->ALARM_BITS[sattr->index];
+       pr_info("doug: nr: %d  ; index %d\n", nr, sattr->index);
        return sprintf(buf, "%u\n",
                       (unsigned int)((data->alarms >> nr) & 0x01));
 }

And for b7f1f7b2523a got (edited):

nct6775_core: doug: nr: 0 ; index 0
nct6775_core: doug: nr: 1 ; index 1
nct6775_core: doug: nr: 2 ; index 2
nct6775_core: doug: nr: 3 ; index 3
nct6775_core: doug: nr: 8 ; index 4
nct6775_core: doug: nr: -1 ; index 5
================================================================================

UBSAN: shift-out-of-bounds in drivers/hwmon/nct6775-core.c:1758:39

shift exponent -1 is negative
...
nct6775_core: doug: nr: 20 ; index 6
nct6775_core: doug: nr: 16 ; index 7
nct6775_core: doug: nr: 17 ; index 8
nct6775_core: doug: nr: 24 ; index 9
nct6775_core: doug: nr: 25 ; index 10
nct6775_core: doug: nr: 26 ; index 11
nct6775_core: doug: nr: 27 ; index 12
nct6775_core: doug: nr: 28 ; index 13
nct6775_core: doug: nr: 29 ; index 14
nct6775_core: doug: nr: 6 ; index 24
nct6775_core: doug: nr: 7 ; index 25
nct6775_core: doug: nr: 11 ; index 26
nct6775_core: doug: nr: 10 ; index 27
nct6775_core: doug: nr: 23 ; index 28
nct6775_core: doug: nr: 33 ; index 29
nct6775_core: doug: nr: 12 ; index 48
nct6775_core: doug: nr: 9 ; index 49

Observe that the table seems to be
NCT6799_ALARM_BITS
But the indexes seem to be for
NCT6779_ALARM_BITS

static const s8 NCT6799_ALARM_BITS[NUM_ALARM_BITS] = {
         0,  1,  2,  3,  8, -1, 20, 16, 17, 24, 25, 26,   /* in0-in11     */
        27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1,   /* in12-in23    */
         6,  7, 11, 10, 23, 33, -1, -1, -1, -1, -1, -1,   /* fan1-fan12   */
         4,  5, 40, 41, 42, 43, 44, -1, -1, -1, -1, -1,   /* temp1-temp12 */
        12,  9,                                           /* intr0-intr1  */
};

Now repeat the test as of 43fbe66dc216:

nct6775_core: doug: nr: 0 ; index 0
nct6775_core: doug: nr: 1 ; index 1
nct6775_core: doug: nr: 2 ; index 2
nct6775_core: doug: nr: 3 ; index 3
nct6775_core: doug: nr: 8 ; index 4
nct6775_core: doug: nr: 21 ; index 5
nct6775_core: doug: nr: 20 ; index 6
nct6775_core: doug: nr: 16 ; index 7
nct6775_core: doug: nr: 17 ; index 8
nct6775_core: doug: nr: 24 ; index 9
nct6775_core: doug: nr: 25 ; index 10
nct6775_core: doug: nr: 26 ; index 11
nct6775_core: doug: nr: 27 ; index 12
nct6775_core: doug: nr: 28 ; index 13
nct6775_core: doug: nr: 29 ; index 14
nct6775_core: doug: nr: 6 ; index 24
nct6775_core: doug: nr: 7 ; index 25
nct6775_core: doug: nr: 11 ; index 26
nct6775_core: doug: nr: 10 ; index 27
nct6775_core: doug: nr: 23 ; index 28
nct6775_core: doug: nr: 33 ; index 29
nct6775_core: doug: nr: 12 ; index 48
nct6775_core: doug: nr: 9 ; index 49

Observe that the table seems to be
NCT6779_ALARM_BITS
And the indexing seems to be for that
Table.

static const s8 NCT6779_ALARM_BITS[NUM_ALARM_BITS] = {
         0,  1,  2,  3,  8, 21, 20, 16, 17, 24, 25, 26,   /* in0-in11     */
        27, 28, 29, -1, -1, -1, -1, -1, -1, -1, -1, -1,   /* in12-in23    */
         6,  7, 11, 10, 23, -1, -1, -1, -1, -1, -1, -1,   /* fan1-fan12   */
         4,  5, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1,   /* temp1-temp12 */
        12,  9,                                           /* intr0-intr1  */
};
Quoted 3 lines

You probably need this information:
nct6775: Found NCT6798D or compatible chip at 0x2e:0x290

Thanks for the regression report. I'm adding it to regzbot:

#regzbot ^introduced: b7f1f7b2523a6a
#regzbot title: shift out-of-bounds in nct6799's additional TEMP registers

Signature · 1 line
An old man doll... just what I always wanted! - Clara
#3 lore raw
In reply to Guenter Roeck

Thanks for the detailed report, Doug.
Would you be able to test out a fix please?

It's a basic guard line as _alarm attributes are assumed to be there when a sensor exists, but the device doesn't have an alarm for in5 (VIN8 on the device)

If you could also confirm that your /sys/class/hwmon/hwmon?/in5_alarm file is there and showing 0, that would be great.

---

drivers/hwmon/nct6775-core.c +3 -0
index 02a7124..5470aff 100644
@@ -1753,6 +1753,9 @@ nct6775_show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
                return PTR_ERR(data);
 
        nr = data->ALARM_BITS[sattr->index];
+       if (nr < 0)
+               return sprintf(buf, "0\n");
+
        return sprintf(buf, "%u\n",
                       (unsigned int)((data->alarms >> nr) & 0x01));
 }

---

More details - if the above patch fixes the issue...

The update of nct6798/nct6799 for additional TEMP sensors required separating them from the previous set of devices.

Both devices are very similar.
Both do not have an alarm bit for VIN8 (index 5) where the shift-out-of-bounds check trips.

Quoted 1 line
Quoted 1 line

nct6775_core: doug: nr: 21 ; index 5

Previously in5_alarm was pointing at bit 21 (which is bit 5 in reg 0x45b) which is reserved and *probably* always 0. With the update, 6798 was pointed at the same ALARM_BITS as 6799 as the TEMP bits are different from other devices.

This is correct and it doesn't need to point back at the old BITS again. However, now I realise that in*_alarm attributes can't be switched off separately from their sensor - in5_* are all there except ALARM.

Seems the shift-out-of-bounds check was there prior to this change. I'm not exactly sure why this didn't come up in my testing on 6.5.0.

This is the only occurrence of non-existent ALARM in the middle of other sensors, so a simple guard check seems to be the reasonable thing here even though it may get evaluated more times than it should.

If it's confirmed to work, I can submit a formal patch later.

Above change tested on nct6799 on 6.5.0-rc2+ with no impact or additional dmesg output.

Quoted 142 lines · Guenter Roeck

Hi,

Quoted 10 lines · Doug Smythies

Kernel 6.6-rc1 has an error during boot. The guilty commit is:
b7f1f7b2523a6a4382f12fe953380b847b80e09d
hwmon: (nct6775) Additional TEMP registers for nct6799

There seems to be confusion between the indexes into the NCT6799_ALARM_BITS array or the NCT6779_ALARM_BITS array. I do not understand the code and do not know if it is the indexing that is reversed or the wrong table is being used.

Thanks a lot for the report. Ahmad, can you look into this ? If it can't be fixed quickly we'll have to revert the offending patch.

Thanks,
Guenter

Quoted 121 lines

The error from kern.log (edited):

================================================================================

UBSAN: shift-out-of-bounds in drivers/hwmon/nct6775-core.c:1757:39
shift exponent -1 is negative
CPU: 9 PID: 822 Comm: sensors Not tainted 6.6.0-rc1-stock2 #1165
Hardware name: ASUS System Product Name/PRIME Z490-A, BIOS 9902 09/15/2021
Call Trace:
<TASK>
dump_stack_lvl+0x48/0x70
dump_stack+0x10/0x20
ubsan_epilogue+0x9/0x40
__ubsan_handle_shift_out_of_bounds+0x10f/0x170

...

I added a "pr_info" line (in the below it was as of the prior commit, 43fbe66dc216 hwmon: Add driver for Renesas HS3001):

doug@s19:~/kernel/linux$ git diff
drivers/hwmon/nct6775-core.c +1 -0
index 33533d95cf48..12e3df84c034 100644
@@ -1727,6 +1727,7 @@ nct6775_show_alarm(struct device *dev, struct 
 device_attribute *attr, char *buf)
                  return PTR_ERR(data);
 
          nr = data->ALARM_BITS[sattr->index];
+       pr_info("doug: nr: %d  ; index %d\n", nr, sattr->index);
          return sprintf(buf, "%u\n",
                         (unsigned int)((data->alarms >> nr) & 0x01));

  }

And for b7f1f7b2523a got (edited):

nct6775_core: doug: nr: 0  ; index 0
nct6775_core: doug: nr: 1  ; index 1
nct6775_core: doug: nr: 2  ; index 2
nct6775_core: doug: nr: 3  ; index 3
nct6775_core: doug: nr: 8  ; index 4
nct6775_core: doug: nr: -1  ; index 5
================================================================================

UBSAN: shift-out-of-bounds in drivers/hwmon/nct6775-core.c:1758:39

shift exponent -1 is negative
...
nct6775_core: doug: nr: 20  ; index 6
nct6775_core: doug: nr: 16  ; index 7
nct6775_core: doug: nr: 17  ; index 8
nct6775_core: doug: nr: 24  ; index 9
nct6775_core: doug: nr: 25  ; index 10
nct6775_core: doug: nr: 26  ; index 11
nct6775_core: doug: nr: 27  ; index 12
nct6775_core: doug: nr: 28  ; index 13
nct6775_core: doug: nr: 29  ; index 14
nct6775_core: doug: nr: 6  ; index 24
nct6775_core: doug: nr: 7  ; index 25
nct6775_core: doug: nr: 11  ; index 26
nct6775_core: doug: nr: 10  ; index 27
nct6775_core: doug: nr: 23  ; index 28
nct6775_core: doug: nr: 33  ; index 29
nct6775_core: doug: nr: 12  ; index 48
nct6775_core: doug: nr: 9  ; index 49

Observe that the table seems to be
NCT6799_ALARM_BITS
But the indexes seem to be for
NCT6779_ALARM_BITS

static const s8 NCT6799_ALARM_BITS[NUM_ALARM_BITS] = {
          0,  1,  2,  3,  8, -1, 20, 16, 17, 24, 25, 26,   /* in0-in11     */ 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1,   /* in12-in23    */ 6,  7, 11, 10, 23, 33, -1, -1, -1, -1, -1, -1,   /* fan1-fan12   */ 4,  5, 40, 41, 42, 43, 44, -1, -1, -1, -1, -1,   /* temp1-temp12 */ 12,  9,                                           /* intr0-intr1  */ };

Now repeat the test as of 43fbe66dc216:

nct6775_core: doug: nr: 0  ; index 0
nct6775_core: doug: nr: 1  ; index 1
nct6775_core: doug: nr: 2  ; index 2
nct6775_core: doug: nr: 3  ; index 3
nct6775_core: doug: nr: 8  ; index 4
nct6775_core: doug: nr: 21  ; index 5
nct6775_core: doug: nr: 20  ; index 6
nct6775_core: doug: nr: 16  ; index 7
nct6775_core: doug: nr: 17  ; index 8
nct6775_core: doug: nr: 24  ; index 9
nct6775_core: doug: nr: 25  ; index 10
nct6775_core: doug: nr: 26  ; index 11
nct6775_core: doug: nr: 27  ; index 12
nct6775_core: doug: nr: 28  ; index 13
nct6775_core: doug: nr: 29  ; index 14
nct6775_core: doug: nr: 6  ; index 24
nct6775_core: doug: nr: 7  ; index 25
nct6775_core: doug: nr: 11  ; index 26
nct6775_core: doug: nr: 10  ; index 27
nct6775_core: doug: nr: 23  ; index 28
nct6775_core: doug: nr: 33  ; index 29
nct6775_core: doug: nr: 12  ; index 48
nct6775_core: doug: nr: 9  ; index 49

Observe that the table seems to be
NCT6779_ALARM_BITS
And the indexing seems to be for that
Table.

static const s8 NCT6779_ALARM_BITS[NUM_ALARM_BITS] = {
          0,  1,  2,  3,  8, 21, 20, 16, 17, 24, 25, 26,   /* in0-in11     */ 27, 28, 29, -1, -1, -1, -1, -1, -1, -1, -1, -1,   /* in12-in23    */ 6,  7, 11, 10, 23, -1, -1, -1, -1, -1, -1, -1,   /* fan1-fan12   */ 4,  5, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1,   /* temp1-temp12 */ 12,  9,                                           /* intr0-intr1  */ };

You probably need this information:
nct6775: Found NCT6798D or compatible chip at 0x2e:0x290

... Doug

Signature · 2 lines
Regards,
Ahmad
maintainer
#4 lore raw
Quoted 47 lines · Ahmad Khalifa

Thanks for the detailed report, Doug.
Would you be able to test out a fix please?

It's a basic guard line as _alarm attributes are assumed to be there when a sensor exists, but the device doesn't have an alarm for in5 (VIN8 on the device)

If you could also confirm that your /sys/class/hwmon/hwmon?/in5_alarm file is there and showing 0, that would be great.

---

drivers/hwmon/nct6775-core.c +3 -1
index 02a7124..5470aff 100644
@@ -1753,6 +1753,9 @@ nct6775_show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
                 return PTR_ERR(data);
 
         nr = data->ALARM_BITS[sattr->index];
+       if (nr < 0)
+               return sprintf(buf, "0\n");
+
         return sprintf(buf, "%u\n",
                        (unsigned int)((data->alarms >> nr) & 0x01));
  }
---

More details - if the above patch fixes the issue...

The update of nct6798/nct6799 for additional TEMP sensors required separating them from the previous set of devices.

Both devices are very similar.
Both do not have an alarm bit for VIN8 (index 5) where the shift-out-of-bounds check trips.

Quoted 1 line
Quoted 1 line

nct6775_core: doug: nr: 21  ; index 5

Previously in5_alarm was pointing at bit 21 (which is bit 5 in reg 0x45b) which is reserved and *probably* always 0. With the update, 6798 was pointed at the same ALARM_BITS as 6799 as the TEMP bits are different from other devices.

This is correct and it doesn't need to point back at the old BITS again. However, now I realise that in*_alarm attributes can't be switched off separately from their sensor - in5_* are all there except ALARM.

Quoted 9 lines

Seems the shift-out-of-bounds check was there prior to this change. I'm not exactly sure why this didn't come up in my testing on 6.5.0.

This is the only occurrence of non-existent ALARM in the middle of other sensors, so a simple guard check seems to be the reasonable thing here even though it may get evaluated more times than it should.

If it's confirmed to work, I can submit a formal patch later.

The proper fix should really be in nct6775_in_is_visible(), which should drop the attribute if there is no alarm bit for it, similar to, for example, nct6775_fan_is_visible(). Something like

	int nr = index % 5;     /* attribute index */

	if (nr == 1 && data->ALARM_BITS[in] == -1)
                return 0;

I think there is a also problem with beep attribute handling, but that is a different bug unrelated to this one.

Guenter

#5 lore raw
Quoted 9 lines · Guenter Roeck

The proper fix should really be in nct6775_in_is_visible(), which should drop the attribute if there is no alarm bit for it, similar to, for example, nct6775_fan_is_visible(). Something like

    int nr = index % 5;     /* attribute index */

    if (nr == 1 && data->ALARM_BITS[in] == -1)
                return 0;

Perfect, that's what I looked for but couldn't figure it out in a rush. If it's confirmed, I'll convert the fix so it hides the attribute instead.

Signature · 2 lines
Regards,
Ahmad
maintainer
#9 lore raw
In reply to Guenter Roeck

On 9/16/23 10:04, Guenter Roeck wrote:
[ ... ]

Quoted 6 lines

The proper fix should really be in nct6775_in_is_visible(), which should drop the attribute if there is no alarm bit for it, similar to, for example, nct6775_fan_is_visible(). Something like

Quoted 8 lines

    int nr = index % 5;     /* attribute index */

    if (nr == 1 && data->ALARM_BITS[in] == -1)
                return 0;

I think there is a also problem with beep attribute handling, but that is a different bug unrelated to this one.

I think beep attributes are ok after all. All voltages have them, and nct6775_fan_is_visible() already checks for beep bits.

Guenter

maintainer
#6 lore raw
In reply to Ahmad Khalifa
Quoted 7 lines · Ahmad Khalifa
Quoted 5 lines · Guenter Roeck

The proper fix should really be in nct6775_in_is_visible(), which should drop the attribute if there is no alarm bit for it, similar to, for example, nct6775_fan_is_visible(). Something like

Quoted 9 lines
Quoted 4 lines

     int nr = index % 5;     /* attribute index */

     if (nr == 1 && data->ALARM_BITS[in] == -1)
                 return 0;

Perfect, that's what I looked for but couldn't figure it out in a rush. If it's confirmed, I'll convert the fix so it hides the attribute instead.

I'd suggest to just send a patch. We can always update it with v2 if a revision is needed.

Thanks,
Guenter

#7 lore raw
Quoted 13 lines · On 2023.09.16 11:11 Guenter wrote:
Quoted 12 lines · Ahmad Khalifa
Quoted 9 lines · Guenter Roeck

The proper fix should really be in nct6775_in_is_visible(), which should drop the attribute if there is no alarm bit for it, similar to, for example, nct6775_fan_is_visible(). Something like

     int nr = index % 5;     /* attribute index */

     if (nr == 1 && data->ALARM_BITS[in] == -1)
                 return 0;
Quoted 7 lines
Quoted 4 lines

Perfect, that's what I looked for but couldn't figure it out in a rush. If it's confirmed, I'll convert the fix so it hides the attribute instead.

I'd suggest to just send a patch. We can always update it with v2 if a revision is needed.

Hi,

And thanks for your quick attention on this.

If I understand all the emails correctly, the above supersedes the previous patch suggestion.

I tested it with kernel 6.6-rc1, and it fixes the issue.

doug@s19:~/kernel/linux$ git diff
drivers/hwmon/nct6775-core.c +7 -0
index 02a71244fc3b..ead5d83f1594 100644
@@ -1753,6 +1753,9 @@ nct6775_show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
                return PTR_ERR(data);
 
        nr = data->ALARM_BITS[sattr->index];
+
+       pr_info("doug: nr: %d  ; index %d\n", nr, sattr->index);
+
        return sprintf(buf, "%u\n",
                       (unsigned int)((data->alarms >> nr) & 0x01));
 }
@@ -1910,6 +1913,10 @@ static umode_t nct6775_in_is_visible(struct kobject *kobj,
        struct device *dev = kobj_to_dev(kobj);
        struct nct6775_data *data = dev_get_drvdata(dev);
        int in = index / 5;     /* voltage index */
+       int nr = index % 5;     /* attribute index */
+
+       if (nr == 1 && data->ALARM_BITS[in] == -1)
+               return 0;
 
        if (!(data->have_in & BIT(in)))
                return 0;

You can see I left my pr_info statement in, and got:

Sep 16 12:16:17 s19 kernel: [    3.091829] nct6775: Found NCT6798D or compatible chip at 0x2e:0x290
...
Sep 16 12:16:17 s19 kernel: [    3.744414] nct6775_core: doug: nr: 0  ; index 0
Sep 16 12:16:17 s19 kernel: [    3.744442] nct6775_core: doug: nr: 1  ; index 1
Sep 16 12:16:17 s19 kernel: [    3.744466] nct6775_core: doug: nr: 2  ; index 2
Sep 16 12:16:17 s19 kernel: [    3.744490] nct6775_core: doug: nr: 3  ; index 3
Sep 16 12:16:17 s19 kernel: [    3.744514] nct6775_core: doug: nr: 8  ; index 4
Sep 16 12:16:17 s19 kernel: [    3.744555] nct6775_core: doug: nr: 20  ; index 6
Sep 16 12:16:17 s19 kernel: [    3.744578] nct6775_core: doug: nr: 16  ; index 7
Sep 16 12:16:17 s19 kernel: [    3.744601] nct6775_core: doug: nr: 17  ; index 8
Sep 16 12:16:17 s19 kernel: [    3.744625] nct6775_core: doug: nr: 24  ; index 9
Sep 16 12:16:17 s19 kernel: [    3.744649] nct6775_core: doug: nr: 25  ; index 10
Sep 16 12:16:17 s19 kernel: [    3.744672] nct6775_core: doug: nr: 26  ; index 11
Sep 16 12:16:17 s19 kernel: [    3.744695] nct6775_core: doug: nr: 27  ; index 12
Sep 16 12:16:17 s19 kernel: [    3.744718] nct6775_core: doug: nr: 28  ; index 13
Sep 16 12:16:17 s19 kernel: [    3.744741] nct6775_core: doug: nr: 29  ; index 14
Sep 16 12:16:17 s19 kernel: [    3.744769] nct6775_core: doug: nr: 6  ; index 24
Sep 16 12:16:17 s19 kernel: [    3.744787] nct6775_core: doug: nr: 7  ; index 25
Sep 16 12:16:17 s19 kernel: [    3.744805] nct6775_core: doug: nr: 11  ; index 26
Sep 16 12:16:17 s19 kernel: [    3.744822] nct6775_core: doug: nr: 10  ; index 27
Sep 16 12:16:17 s19 kernel: [    3.744846] nct6775_core: doug: nr: 23  ; index 28
Sep 16 12:16:17 s19 kernel: [    3.744866] nct6775_core: doug: nr: 33  ; index 29
Sep 16 12:16:17 s19 kernel: [    3.752903] nct6775_core: doug: nr: 12  ; index 48
Sep 16 12:16:17 s19 kernel: [    3.752913] nct6775_core: doug: nr: 9  ; index 49

...

... Doug

maintainer
#8 lore raw
Quoted 22 lines · Doug Smythies
Quoted 13 lines · On 2023.09.16 11:11 Guenter wrote:
Quoted 12 lines · Ahmad Khalifa
Quoted 9 lines · Guenter Roeck

The proper fix should really be in nct6775_in_is_visible(), which should drop the attribute if there is no alarm bit for it, similar to, for example, nct6775_fan_is_visible(). Something like

      int nr = index % 5;     /* attribute index */

      if (nr == 1 && data->ALARM_BITS[in] == -1)
                  return 0;
Quoted 7 lines
Quoted 4 lines

Perfect, that's what I looked for but couldn't figure it out in a rush. If it's confirmed, I'll convert the fix so it hides the attribute instead.

I'd suggest to just send a patch. We can always update it with v2 if a revision is needed.

Quoted 9 lines

Hi,

And thanks for your quick attention on this.

If I understand all the emails correctly, the above supersedes the previous patch suggestion.

I tested it with kernel 6.6-rc1, and it fixes the issue.

Excellent, thanks a lot for testing!

Guenter

Quoted 58 lines
doug@s19:~/kernel/linux$ git diff
drivers/hwmon/nct6775-core.c +7 -0
index 02a71244fc3b..ead5d83f1594 100644
@@ -1753,6 +1753,9 @@ nct6775_show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
                 return PTR_ERR(data);
 
         nr = data->ALARM_BITS[sattr->index];
+
+       pr_info("doug: nr: %d  ; index %d\n", nr, sattr->index);
+
         return sprintf(buf, "%u\n",
                        (unsigned int)((data->alarms >> nr) & 0x01));
  }
@@ -1910,6 +1913,10 @@ static umode_t nct6775_in_is_visible(struct kobject *kobj,
         struct device *dev = kobj_to_dev(kobj);
         struct nct6775_data *data = dev_get_drvdata(dev);
         int in = index / 5;     /* voltage index */
+       int nr = index % 5;     /* attribute index */
+
+       if (nr == 1 && data->ALARM_BITS[in] == -1)
+               return 0;
 
         if (!(data->have_in & BIT(in)))
                 return 0;

You can see I left my pr_info statement in, and got:

Sep 16 12:16:17 s19 kernel: [    3.091829] nct6775: Found NCT6798D or compatible chip at 0x2e:0x290
...
Sep 16 12:16:17 s19 kernel: [    3.744414] nct6775_core: doug: nr: 0  ; index 0
Sep 16 12:16:17 s19 kernel: [    3.744442] nct6775_core: doug: nr: 1  ; index 1
Sep 16 12:16:17 s19 kernel: [    3.744466] nct6775_core: doug: nr: 2  ; index 2
Sep 16 12:16:17 s19 kernel: [    3.744490] nct6775_core: doug: nr: 3  ; index 3
Sep 16 12:16:17 s19 kernel: [    3.744514] nct6775_core: doug: nr: 8  ; index 4
Sep 16 12:16:17 s19 kernel: [    3.744555] nct6775_core: doug: nr: 20  ; index 6
Sep 16 12:16:17 s19 kernel: [    3.744578] nct6775_core: doug: nr: 16  ; index 7
Sep 16 12:16:17 s19 kernel: [    3.744601] nct6775_core: doug: nr: 17  ; index 8
Sep 16 12:16:17 s19 kernel: [    3.744625] nct6775_core: doug: nr: 24  ; index 9
Sep 16 12:16:17 s19 kernel: [    3.744649] nct6775_core: doug: nr: 25  ; index 10
Sep 16 12:16:17 s19 kernel: [    3.744672] nct6775_core: doug: nr: 26  ; index 11
Sep 16 12:16:17 s19 kernel: [    3.744695] nct6775_core: doug: nr: 27  ; index 12
Sep 16 12:16:17 s19 kernel: [    3.744718] nct6775_core: doug: nr: 28  ; index 13
Sep 16 12:16:17 s19 kernel: [    3.744741] nct6775_core: doug: nr: 29  ; index 14
Sep 16 12:16:17 s19 kernel: [    3.744769] nct6775_core: doug: nr: 6  ; index 24
Sep 16 12:16:17 s19 kernel: [    3.744787] nct6775_core: doug: nr: 7  ; index 25
Sep 16 12:16:17 s19 kernel: [    3.744805] nct6775_core: doug: nr: 11  ; index 26
Sep 16 12:16:17 s19 kernel: [    3.744822] nct6775_core: doug: nr: 10  ; index 27
Sep 16 12:16:17 s19 kernel: [    3.744846] nct6775_core: doug: nr: 23  ; index 28
Sep 16 12:16:17 s19 kernel: [    3.744866] nct6775_core: doug: nr: 33  ; index 29
Sep 16 12:16:17 s19 kernel: [    3.752903] nct6775_core: doug: nr: 12  ; index 48
Sep 16 12:16:17 s19 kernel: [    3.752913] nct6775_core: doug: nr: 9  ; index 49

...

... Doug

#10 lore raw
In reply to Ahmad Khalifa

Hi Ahmad,

Quoted 3 lines · On 2023.09.16 009:43 Ahmad wrote:

Thanks for the detailed report, Doug.
Would you be able to test out a fix please?

That request was superseded by a subsequent email, already replied to.

Quoted 6 lines

It's a basic guard line as _alarm attributes are assumed to be there when a sensor exists, but the device doesn't have an alarm for in5 (VIN8 on the device)

If you could also confirm that your /sys/class/hwmon/hwmon?/in5_alarm file is there and showing 0, that would be great.

But I forgot to reply to that part:

The file is there, and the content is 0.

$ ls -l /sys/class/hwmon/hwmon?/in5_alarm
-r--r--r-- 1 root root 4096 Sep 17 14:14 /sys/class/hwmon/hwmon3/in5_alarm
doug@s19:~$ ls -l /sys/devices/platform/eeepc-wmi/hwmon/hwmon4^C
doug@s19:~$ cat /sys/class/hwmon/hwmon?/in5_alarm
0

I had to go back to an unpatched kernel 6.6-rc1 for the above.
With the kernel I compiled yesterday for the test patch, the file was not there.

... Doug

#11 lore raw
Quoted 1 line · Doug Smythies

With the kernel I compiled yesterday for the test patch, the file was not there.

That's the better approach, the file shouldn't exist.
Would you like to submit that patch then? I can test it and reply with a "Tested-by" tag after. If not, happy to submit one.

Signature · 2 lines
Regards,
Ahmad
maintainer
#12 lore raw
Quoted 7 lines · Ahmad Khalifa
Quoted 1 line · Doug Smythies

With the kernel I compiled yesterday for the test patch, the file was not there.

That's the better approach, the file shouldn't exist.
Would you like to submit that patch then? I can test it and reply with a "Tested-by" tag after. If not, happy to submit one.

I was waiting for you to submit the patch. Please do.

Thanks,
Guenter

#14 lore raw
In reply to Bagas Sanjaya

[TLDR: This mail in primarily relevant for Linux kernel regression tracking. See link in footer if these mails annoy you.]

Quoted 9 lines · Bagas Sanjaya
Quoted 3 lines · Doug Smythies

Kernel 6.6-rc1 has an error during boot. The guilty commit is:
b7f1f7b2523a6a4382f12fe953380b847b80e09d
hwmon: (nct6775) Additional TEMP registers for nct6799

[...]
Thanks for the regression report. I'm adding it to regzbot:

#regzbot ^introduced: b7f1f7b2523a6a
#regzbot title: shift out-of-bounds in nct6799's additional TEMP registers

Fix doesn't use a link regzbot is able to handle, thus point to it manually:

#regzbot fix: hwmon: (nct6775) Fix non-existent ALARM warning #regzbot ignore-activity

Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat) --
Everything you wanna know about Linux kernel regression tracking:
https://linux-regtracking.leemhuis.info/about/#tldr
That page also explains what to do if mails like this annoy you.