Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

eth: fbnic: Revert "eth: fbnic: Add hardware monitoring support via HWMON interface"

There is a garbage value problem in fbnic_mac_get_sensor_asic(). 'fw_cmpl'
is uninitialized which makes 'sensor' and '*val' to be stored garbage
value. Revert commit d85ebade02e8 ("eth: fbnic: Add hardware monitoring
support via HWMON interface") to avoid this problem.

Fixes: d85ebade02e8 ("eth: fbnic: Add hardware monitoring support via HWMON interface")
Signed-off-by: Su Hui <suhui@nfschina.com>
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Suggested-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Link: https://patch.msgid.link/20250106023647.47756-1-suhui@nfschina.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Su Hui and committed by
Jakub Kicinski
95978931 fd48f071

-126
-1
drivers/net/ethernet/meta/fbnic/Makefile
··· 13 13 fbnic_ethtool.o \ 14 14 fbnic_fw.o \ 15 15 fbnic_hw_stats.o \ 16 - fbnic_hwmon.o \ 17 16 fbnic_irq.o \ 18 17 fbnic_mac.o \ 19 18 fbnic_netdev.o \
-5
drivers/net/ethernet/meta/fbnic/fbnic.h
··· 20 20 struct device *dev; 21 21 struct net_device *netdev; 22 22 struct dentry *dbg_fbd; 23 - struct device *hwmon; 24 23 25 24 u32 __iomem *uc_addr0; 26 25 u32 __iomem *uc_addr4; ··· 32 33 33 34 struct fbnic_fw_mbx mbx[FBNIC_IPC_MBX_INDICES]; 34 35 struct fbnic_fw_cap fw_cap; 35 - struct fbnic_fw_completion *cmpl_data; 36 36 /* Lock protecting Tx Mailbox queue to prevent possible races */ 37 37 spinlock_t fw_tx_lock; 38 38 ··· 139 141 140 142 int fbnic_fw_enable_mbx(struct fbnic_dev *fbd); 141 143 void fbnic_fw_disable_mbx(struct fbnic_dev *fbd); 142 - 143 - void fbnic_hwmon_register(struct fbnic_dev *fbd); 144 - void fbnic_hwmon_unregister(struct fbnic_dev *fbd); 145 144 146 145 int fbnic_pcs_irq_enable(struct fbnic_dev *fbd); 147 146 void fbnic_pcs_irq_disable(struct fbnic_dev *fbd);
-7
drivers/net/ethernet/meta/fbnic/fbnic_fw.h
··· 44 44 u8 link_fec; 45 45 }; 46 46 47 - struct fbnic_fw_completion { 48 - struct { 49 - s32 millivolts; 50 - s32 millidegrees; 51 - } tsene; 52 - }; 53 - 54 47 void fbnic_mbx_init(struct fbnic_dev *fbd); 55 48 void fbnic_mbx_clean(struct fbnic_dev *fbd); 56 49 void fbnic_mbx_poll(struct fbnic_dev *fbd);
-81
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* Copyright (c) Meta Platforms, Inc. and affiliates. */ 3 - 4 - #include <linux/hwmon.h> 5 - 6 - #include "fbnic.h" 7 - #include "fbnic_mac.h" 8 - 9 - static int fbnic_hwmon_sensor_id(enum hwmon_sensor_types type) 10 - { 11 - if (type == hwmon_temp) 12 - return FBNIC_SENSOR_TEMP; 13 - if (type == hwmon_in) 14 - return FBNIC_SENSOR_VOLTAGE; 15 - 16 - return -EOPNOTSUPP; 17 - } 18 - 19 - static umode_t fbnic_hwmon_is_visible(const void *drvdata, 20 - enum hwmon_sensor_types type, 21 - u32 attr, int channel) 22 - { 23 - if (type == hwmon_temp && attr == hwmon_temp_input) 24 - return 0444; 25 - if (type == hwmon_in && attr == hwmon_in_input) 26 - return 0444; 27 - 28 - return 0; 29 - } 30 - 31 - static int fbnic_hwmon_read(struct device *dev, enum hwmon_sensor_types type, 32 - u32 attr, int channel, long *val) 33 - { 34 - struct fbnic_dev *fbd = dev_get_drvdata(dev); 35 - const struct fbnic_mac *mac = fbd->mac; 36 - int id; 37 - 38 - id = fbnic_hwmon_sensor_id(type); 39 - return id < 0 ? id : mac->get_sensor(fbd, id, val); 40 - } 41 - 42 - static const struct hwmon_ops fbnic_hwmon_ops = { 43 - .is_visible = fbnic_hwmon_is_visible, 44 - .read = fbnic_hwmon_read, 45 - }; 46 - 47 - static const struct hwmon_channel_info *fbnic_hwmon_info[] = { 48 - HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT), 49 - HWMON_CHANNEL_INFO(in, HWMON_I_INPUT), 50 - NULL 51 - }; 52 - 53 - static const struct hwmon_chip_info fbnic_chip_info = { 54 - .ops = &fbnic_hwmon_ops, 55 - .info = fbnic_hwmon_info, 56 - }; 57 - 58 - void fbnic_hwmon_register(struct fbnic_dev *fbd) 59 - { 60 - if (!IS_REACHABLE(CONFIG_HWMON)) 61 - return; 62 - 63 - fbd->hwmon = hwmon_device_register_with_info(fbd->dev, "fbnic", 64 - fbd, &fbnic_chip_info, 65 - NULL); 66 - if (IS_ERR(fbd->hwmon)) { 67 - dev_notice(fbd->dev, 68 - "Failed to register hwmon device %pe\n", 69 - fbd->hwmon); 70 - fbd->hwmon = NULL; 71 - } 72 - } 73 - 74 - void fbnic_hwmon_unregister(struct fbnic_dev *fbd) 75 - { 76 - if (!IS_REACHABLE(CONFIG_HWMON) || !fbd->hwmon) 77 - return; 78 - 79 - hwmon_device_unregister(fbd->hwmon); 80 - fbd->hwmon = NULL; 81 - }
-22
drivers/net/ethernet/meta/fbnic/fbnic_mac.c
··· 686 686 MAC_STAT_TX_BROADCAST); 687 687 } 688 688 689 - static int fbnic_mac_get_sensor_asic(struct fbnic_dev *fbd, int id, long *val) 690 - { 691 - struct fbnic_fw_completion fw_cmpl; 692 - s32 *sensor; 693 - 694 - switch (id) { 695 - case FBNIC_SENSOR_TEMP: 696 - sensor = &fw_cmpl.tsene.millidegrees; 697 - break; 698 - case FBNIC_SENSOR_VOLTAGE: 699 - sensor = &fw_cmpl.tsene.millivolts; 700 - break; 701 - default: 702 - return -EINVAL; 703 - } 704 - 705 - *val = *sensor; 706 - 707 - return 0; 708 - } 709 - 710 689 static const struct fbnic_mac fbnic_mac_asic = { 711 690 .init_regs = fbnic_mac_init_regs, 712 691 .pcs_enable = fbnic_pcs_enable_asic, ··· 695 716 .get_eth_mac_stats = fbnic_mac_get_eth_mac_stats, 696 717 .link_down = fbnic_mac_link_down_asic, 697 718 .link_up = fbnic_mac_link_up_asic, 698 - .get_sensor = fbnic_mac_get_sensor_asic, 699 719 }; 700 720 701 721 /**
-7
drivers/net/ethernet/meta/fbnic/fbnic_mac.h
··· 47 47 #define FBNIC_LINK_MODE_PAM4 (FBNIC_LINK_50R1) 48 48 #define FBNIC_LINK_MODE_MASK (FBNIC_LINK_AUTO - 1) 49 49 50 - enum fbnic_sensor_id { 51 - FBNIC_SENSOR_TEMP, /* Temp in millidegrees Centigrade */ 52 - FBNIC_SENSOR_VOLTAGE, /* Voltage in millivolts */ 53 - }; 54 - 55 50 /* This structure defines the interface hooks for the MAC. The MAC hooks 56 51 * will be configured as a const struct provided with a set of function 57 52 * pointers. ··· 83 88 84 89 void (*link_down)(struct fbnic_dev *fbd); 85 90 void (*link_up)(struct fbnic_dev *fbd, bool tx_pause, bool rx_pause); 86 - 87 - int (*get_sensor)(struct fbnic_dev *fbd, int id, long *val); 88 91 }; 89 92 90 93 int fbnic_mac_init(struct fbnic_dev *fbd);
-3
drivers/net/ethernet/meta/fbnic/fbnic_pci.c
··· 296 296 /* Capture snapshot of hardware stats so netdev can calculate delta */ 297 297 fbnic_reset_hw_stats(fbd); 298 298 299 - fbnic_hwmon_register(fbd); 300 - 301 299 if (!fbd->dsn) { 302 300 dev_warn(&pdev->dev, "Reading serial number failed\n"); 303 301 goto init_failure_mode; ··· 358 360 fbnic_netdev_free(fbd); 359 361 } 360 362 361 - fbnic_hwmon_unregister(fbd); 362 363 fbnic_dbg_fbd_exit(fbd); 363 364 fbnic_devlink_unregister(fbd); 364 365 fbnic_fw_disable_mbx(fbd);