@@ -249,7 +249,8 @@ static int ft260_hid_feature_report_get(struct hid_device *hdev,
ret = hid_hw_raw_request(hdev, report_id, buf, len, HID_FEATURE_REPORT,
HID_REQ_GET_REPORT);
- memcpy(data, buf, len);
+ if (likely(ret == len))
+ memcpy(data, buf, len);
kfree(buf);
return ret;
}
@@ -295,12 +296,16 @@ static int ft260_xfer_status(struct ft260_device *dev)
struct hid_device *hdev = dev->hdev;
struct ft260_get_i2c_status_report report;
int ret;
+ int len = sizeof(report);
ret = ft260_hid_feature_report_get(hdev, FT260_I2C_STATUS,
- (u8 *)&report, sizeof(report));
- if (ret < 0) {
+ (u8 *)&report, len);
+ if (unlikely(ret != len)) {
hid_err(hdev, "failed to retrieve status: %d\n", ret);
- return ret;
+ if (ret >= 0)
+ return -EIO;
+ else
+ return ret;
}
dev->clock = le16_to_cpu(report.clock);
@@ -724,10 +729,12 @@ static int ft260_get_system_config(struct hid_device *hdev,
ret = ft260_hid_feature_report_get(hdev, FT260_SYSTEM_SETTINGS,
(u8 *)cfg, len);
- if (ret != len) {
+ if (unlikely(ret != len)) {
hid_err(hdev, "failed to retrieve system status\n");
if (ret >= 0)
return -EIO;
+ else
+ return ret;
}
return 0;
}
@@ -780,8 +787,12 @@ static int ft260_byte_show(struct hid_device *hdev, int id, u8 *cfg, int len,
int ret;
ret = ft260_hid_feature_report_get(hdev, id, cfg, len);
- if (ret != len && ret >= 0)
- return -EIO;
+ if (unlikely(ret != len)) {
+ if (ret >= 0)
+ return -EIO;
+ else
+ return ret;
+ }
return scnprintf(buf, PAGE_SIZE, "%hi\n", *field);
}
@@ -792,8 +803,12 @@ static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len,
int ret;
ret = ft260_hid_feature_report_get(hdev, id, cfg, len);
- if (ret != len && ret >= 0)
- return -EIO;
+ if (unlikely(ret != len)) {
+ if (ret >= 0)
+ return -EIO;
+ else
+ return ret;
+ }
return scnprintf(buf, PAGE_SIZE, "%hi\n", le16_to_cpu(*field));
}
@@ -919,6 +934,7 @@ static int ft260_probe(struct hid_device *hdev, const struct hid_device_id *id)
struct ft260_device *dev;
struct ft260_get_chip_version_report version;
int ret;
+ int len;
dev = devm_kzalloc(&hdev->dev, sizeof(*dev), GFP_KERNEL);
if (!dev)
@@ -942,9 +958,10 @@ static int ft260_probe(struct hid_device *hdev, const struct hid_device_id *id)
goto err_hid_stop;
}
+ len = sizeof(version);
ret = ft260_hid_feature_report_get(hdev, FT260_CHIP_VERSION,
- (u8 *)&version, sizeof(version));
- if (ret != sizeof(version)) {
+ (u8 *)&version, len);
+ if (unlikely(ret != len)) {
hid_err(hdev, "failed to retrieve chip version\n");
if (ret >= 0)
ret = -EIO;