[bug report] phy: realtek: usb: Add driver for the Realtek SoC USB 2.0 PHY
Dan Carpenter
dan.carpenter at linaro.org
Fri Jul 28 04:04:02 PDT 2023
Hello Stanley Chang,
The patch 134e6d25f6bd: "phy: realtek: usb: Add driver for the
Realtek SoC USB 2.0 PHY" from Jul 25, 2023 (linux-next), leads to the
following Smatch static checker warning:
drivers/phy/realtek/phy-rtk-usb2.c:901 get_phy_data_by_efuse()
error: 'buf' dereferencing possible ERR_PTR()
drivers/phy/realtek/phy-rtk-usb3.c:460
get_phy_data_by_efuse() error: 'buf' dereferencing possible ERR_PTR()
drivers/phy/realtek/phy-rtk-usb2.c
878 static int get_phy_data_by_efuse(struct rtk_phy *rtk_phy,
879 struct phy_parameter *phy_parameter, int index)
880 {
881 struct phy_cfg *phy_cfg = rtk_phy->phy_cfg;
882 u8 value = 0;
883 struct nvmem_cell *cell;
884 struct soc_device_attribute rtk_soc_groot[] = {
885 { .family = "Realtek Groot",},
886 { /* empty */ } };
887
888 if (!phy_cfg->check_efuse)
889 goto out;
890
891 /* Read efuse for usb dc cal */
892 cell = nvmem_cell_get(rtk_phy->dev, "usb-dc-cal");
893 if (IS_ERR(cell)) {
894 dev_dbg(rtk_phy->dev, "%s no usb-dc-cal: %ld\n",
895 __func__, PTR_ERR(cell));
896 } else {
897 unsigned char *buf;
898 size_t buf_size;
899
900 buf = nvmem_cell_read(cell, &buf_size);
nvmem_cell_read() can fail.
Sometimes, it's okay ot ignore errors, like if your reads from PCI start
failing, then there is nothing we can do as a kernel. The user needs to
buy new hardware. We need the serenity to ignore the things we cannot
fix.
But here the allocation can fail. So that needs to be checked and
handled correctly.
--> 901 value = buf[0] & phy_cfg->dc_driving_mask;
^^^^^^
warning
902
903 kfree(buf);
904 nvmem_cell_put(cell);
905 }
906
regards,
dan carpenter
More information about the linux-phy
mailing list