Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756620AbcK2Mzk (ORCPT ); Tue, 29 Nov 2016 07:55:40 -0500 Received: from m50-132.163.com ([123.125.50.132]:42458 "EHLO m50-132.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754236AbcK2Mzc (ORCPT ); Tue, 29 Nov 2016 07:55:32 -0500 From: Pan Bian To: linux-usb@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] usb: return correct errno on failures Date: Tue, 29 Nov 2016 20:55:12 +0800 Message-Id: <1480424112-24975-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DNGowABnzsq9ej1YelmqHg--.36311S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrZF4kXr1rKrWfCw1rGFy5twb_yoWktrb_ur WxArnrur48CF4DJ3WrJanYyrWjga1DuFn5Xa9Yq343AF1Yyw1fWrW7ZrnxAr1xXa9Ig3yk Kwn0qw13Ars3CjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUnu6zUUUUUU== X-Originating-IP: [222.131.246.88] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBZB8xclQG6zsw7QAAsn Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1161 Lines: 29 In function __wa_xfer_setup_segs(), variable result takes the return value. Its value should be a negative errno on failures. Because result may be reassigned in a loop, and its value is guaranteed to be not less than 0 during the following repeats of the loop. So when the call to kmalloc() or usb_alloc_urb() fails in the loop, the value of variable result may be 0 (indicates no error), which is inconsistent with the execution status. This patch fixes the bug, initializing variable result with -ENOMEM in the loop. Signed-off-by: Pan Bian --- drivers/usb/wusbcore/wa-xfer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c index 167fcc71..e70322b 100644 --- a/drivers/usb/wusbcore/wa-xfer.c +++ b/drivers/usb/wusbcore/wa-xfer.c @@ -1203,6 +1203,7 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) sizeof(struct wa_xfer_packet_info_hwaiso) + (seg_isoc_frame_count * sizeof(__le16)); } + result = -ENOMEM; seg = xfer->seg[cnt] = kmalloc(alloc_size + iso_pkt_descr_size, GFP_ATOMIC); if (seg == NULL) -- 1.9.1