提交 e26eaf45 编写于 作者: C Claudiu Beznea 提交者: Greg Kroah-Hartman

Staging: wlan-ng: memory allocated inside mkimage() is not freed if subsequent calls fails.

This patch frees memory allocated inside mkimage() in case mkimage()
or any other subsequent calls inside prism2_fwapply() from prism2fw.c
file fails. To fix this I introduces goto labels where the free
operation is done in case some operations fails. After the introduction
of goto labels has been done, in order to use the same return path,
"return x" instuctions were replaced with "goto" instuctions.
Signed-off-by: NClaudiu Beznea <claudiu.beznea@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 02e02048
...@@ -278,7 +278,8 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr, ...@@ -278,7 +278,8 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr,
/* Build the PDA we're going to use. */ /* Build the PDA we're going to use. */
if (read_cardpda(&pda, wlandev)) { if (read_cardpda(&pda, wlandev)) {
netdev_err(wlandev->netdev, "load_cardpda failed, exiting.\n"); netdev_err(wlandev->netdev, "load_cardpda failed, exiting.\n");
return 1; result = 1;
goto out;
} }
/* read the card's PRI-SUP */ /* read the card's PRI-SUP */
...@@ -315,55 +316,58 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr, ...@@ -315,55 +316,58 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr,
if (result) { if (result) {
netdev_err(wlandev->netdev, netdev_err(wlandev->netdev,
"Failed to read the data exiting.\n"); "Failed to read the data exiting.\n");
return 1; goto out;
} }
result = validate_identity(); result = validate_identity();
if (result) { if (result) {
netdev_err(wlandev->netdev, "Incompatible firmware image.\n"); netdev_err(wlandev->netdev, "Incompatible firmware image.\n");
return 1; goto out;
} }
if (startaddr == 0x00000000) { if (startaddr == 0x00000000) {
netdev_err(wlandev->netdev, netdev_err(wlandev->netdev,
"Can't RAM download a Flash image!\n"); "Can't RAM download a Flash image!\n");
return 1; result = 1;
goto out;
} }
/* Make the image chunks */ /* Make the image chunks */
result = mkimage(fchunk, &nfchunks); result = mkimage(fchunk, &nfchunks);
if (result) { if (result) {
netdev_err(wlandev->netdev, "Failed to make image chunk.\n"); netdev_err(wlandev->netdev, "Failed to make image chunk.\n");
return 1; goto free_chunks;
} }
/* Do any plugging */ /* Do any plugging */
result = plugimage(fchunk, nfchunks, s3plug, ns3plug, &pda); result = plugimage(fchunk, nfchunks, s3plug, ns3plug, &pda);
if (result) { if (result) {
netdev_err(wlandev->netdev, "Failed to plug data.\n"); netdev_err(wlandev->netdev, "Failed to plug data.\n");
return 1; goto free_chunks;
} }
/* Insert any CRCs */ /* Insert any CRCs */
if (crcimage(fchunk, nfchunks, s3crc, ns3crc)) { result = crcimage(fchunk, nfchunks, s3crc, ns3crc);
if (result) {
netdev_err(wlandev->netdev, "Failed to insert all CRCs\n"); netdev_err(wlandev->netdev, "Failed to insert all CRCs\n");
return 1; goto free_chunks;
} }
/* Write the image */ /* Write the image */
result = writeimage(wlandev, fchunk, nfchunks); result = writeimage(wlandev, fchunk, nfchunks);
if (result) { if (result) {
netdev_err(wlandev->netdev, "Failed to ramwrite image data.\n"); netdev_err(wlandev->netdev, "Failed to ramwrite image data.\n");
return 1; goto free_chunks;
} }
netdev_info(wlandev->netdev, "prism2_usb: firmware loading finished.\n");
free_chunks:
/* clear any allocated memory */ /* clear any allocated memory */
free_chunks(fchunk, &nfchunks); free_chunks(fchunk, &nfchunks);
free_srecs(); free_srecs();
netdev_info(wlandev->netdev, "prism2_usb: firmware loading finished.\n"); out:
return result; return result;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册