Skip to content

Commit d69753f

Browse files
Edwin Peerdavem330
authored andcommitted
bnxt_en: return proper error codes in bnxt_show_temp
Returning "unknown" as a temperature value violates the hwmon interface rules. Appropriate error codes should be returned via device_attribute show instead. These will ultimately be propagated to the user via the file system interface. In addition to the corrected error handling, it is an even better idea to not present the sensor in sysfs at all if it is known that the read will definitely fail. Given that temp1_input is currently the only sensor reported, ensure no hwmon registration if TEMP_MONITOR_QUERY is not supported or if it will fail due to access permissions. Something smarter may be needed if and when other sensors are added. Fixes: 12cce90 ("bnxt_en: fix HWRM error when querying VF temperature") Signed-off-by: Edwin Peer <edwin.peer@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 492adcf commit d69753f

File tree

1 file changed

+13
-6
lines changed
  • drivers/net/ethernet/broadcom/bnxt

1 file changed

+13
-6
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9311,18 +9311,16 @@ static ssize_t bnxt_show_temp(struct device *dev,
93119311
struct hwrm_temp_monitor_query_output *resp;
93129312
struct bnxt *bp = dev_get_drvdata(dev);
93139313
u32 len = 0;
9314+
int rc;
93149315

93159316
resp = bp->hwrm_cmd_resp_addr;
93169317
bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TEMP_MONITOR_QUERY, -1, -1);
93179318
mutex_lock(&bp->hwrm_cmd_lock);
9318-
if (!_hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT))
9319+
rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
9320+
if (!rc)
93199321
len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */
93209322
mutex_unlock(&bp->hwrm_cmd_lock);
9321-
9322-
if (len)
9323-
return len;
9324-
9325-
return sprintf(buf, "unknown\n");
9323+
return rc ?: len;
93269324
}
93279325
static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0);
93289326

@@ -9342,7 +9340,16 @@ static void bnxt_hwmon_close(struct bnxt *bp)
93429340

93439341
static void bnxt_hwmon_open(struct bnxt *bp)
93449342
{
9343+
struct hwrm_temp_monitor_query_input req = {0};
93459344
struct pci_dev *pdev = bp->pdev;
9345+
int rc;
9346+
9347+
bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TEMP_MONITOR_QUERY, -1, -1);
9348+
rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
9349+
if (rc == -EACCES || rc == -EOPNOTSUPP) {
9350+
bnxt_hwmon_close(bp);
9351+
return;
9352+
}
93469353

93479354
if (bp->hwmon_dev)
93489355
return;

0 commit comments

Comments
 (0)