fix: resolve chip firmware paths through the firmware API

Follow up issue #117: use each module chip enum and the real Wi-Fi device, preserve flat-layout fallback on missing files, and handle allocation and size failures. Based on the report by ggorbi99-dev.
This commit is contained in:
Shen Mintao committed 2026-10-30 09:36:33 +08:00
1 parent 4536a96e48
commit d59217c143
4 files changed
+329 -20

No files matched your search

+57 -10
View File
@@ -249,6 +249,52 @@ void aic_bt_platform_deinit(struct aic_usb_dev *usbdev)
#define MD5(x) x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10],x[11],x[12],x[13],x[14],x[15]
#define MD5PINRT "file md5:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\r\n"
#ifdef CONFIG_USE_FW_REQUEST
static int aic_request_firmware(const struct firmware **fw, const char *name,
struct device *device)
{
#if defined(CONFIG_PLATFORM_UBUNTU) && defined(AICWF_USB_SUPPORT)
struct aicwf_bus *bus = device ? dev_get_drvdata(device) : NULL;
struct aic_usb_dev *usbdev = bus ? bus->bus_priv.usb : NULL;
const char *dir = NULL;
char path[256];
int ret;
if (usbdev) {
switch (usbdev->chipid) {
case PRODUCT_ID_AIC8800:
case PRODUCT_ID_AIC8801:
dir = "aic8800";
break;
case PRODUCT_ID_AIC8800DC:
case PRODUCT_ID_AIC8800DW:
dir = "aic8800DC";
break;
case PRODUCT_ID_AIC8800D80:
case PRODUCT_ID_AIC8800D81:
dir = "aic8800D80";
break;
case PRODUCT_ID_AIC8800D80X2:
case PRODUCT_ID_AIC8800D81X2:
case PRODUCT_ID_AIC8800D89X2:
case PRODUCT_ID_AIC8800D40X2:
dir = "aic8800D80X2";
break;
}
}
if (dir) {
if (snprintf(path, sizeof(path), "%s/%s", dir, name) >= sizeof(path))
return -ENAMETOOLONG;
ret = request_firmware(fw, path, device);
/* Keep flat firmware layouts, without hiding other load errors. */
if (ret != -ENOENT)
return ret;
}
#endif
return request_firmware(fw, name, device);
}
#endif
static int aic_load_firmware(u32 ** fw_buf, const char *name, struct device *device)
{
@@ -264,26 +310,27 @@ static int aic_load_firmware(u32 ** fw_buf, const char *name, struct device *dev
printk("%s: request firmware = %s \n", __func__ ,name);
ret = request_firmware(&fw, name, NULL);
*fw_buf = NULL;
ret = aic_request_firmware(&fw, name, device);
if (ret < 0) {
printk("Load %s fail\n", name);
release_firmware(fw);
return -1;
return ret;
}
size = fw->size;
dst = (u32 *)fw->data;
if (size <= 0) {
if (!fw->size || fw->size > INT_MAX) {
printk("wrong size of firmware file\n");
release_firmware(fw);
return -1;
return -EINVAL;
}
size = fw->size;
dst = (u32 *)fw->data;
buffer = vmalloc(size);
memset(buffer, 0, size);
if (!buffer) {
release_firmware(fw);
return -ENOMEM;
}
memcpy(buffer, dst, size);
*fw_buf = buffer;