Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932658AbcK2M42 (ORCPT ); Tue, 29 Nov 2016 07:56:28 -0500 Received: from m50-138.163.com ([123.125.50.138]:36689 "EHLO m50-138.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754236AbcK2M4S (ORCPT ); Tue, 29 Nov 2016 07:56:18 -0500 From: Pan Bian To: linux-usb@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] usb: fix improper return value when kzalloc fails Date: Tue, 29 Nov 2016 20:56:10 +0800 Message-Id: <1480424170-25018-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: C9GowAC33w_rej1YHrILHw--.44413S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrKw1fJFWUJr1xKrWxur1DGFg_yoWftFb_JF WUJrsrKw4vkFyUJF1Yyas8ZrZ5Ka1UZFn5ZFsYq343AF1jyr18Jryvvrn3AFWxW3yI9FWD Wr1DZ343uF1xujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUnuc_DUUUUU== X-Originating-IP: [222.131.246.88] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiNg0xclWBUaJDgAAAsc Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 927 Lines: 27 The comment says function wa_nep_queue() should return 0 if ok, and <0 errno code on error. However, its implementation always returns 0, even if the call to kzalloc() fails. As a result, the return value may be inconsistent with the execution status, which may mislead the callers. This patch fixes the bug, returning -ENOMEM when the call to kzalloc() fails. Signed-off-by: Pan Bian --- drivers/usb/wusbcore/wa-nep.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/wusbcore/wa-nep.c b/drivers/usb/wusbcore/wa-nep.c index ed46222..e3819fc 100644 --- a/drivers/usb/wusbcore/wa-nep.c +++ b/drivers/usb/wusbcore/wa-nep.c @@ -198,6 +198,7 @@ static int wa_nep_queue(struct wahc *wa, size_t size) if (nw == NULL) { if (printk_ratelimit()) dev_err(dev, "No memory to queue notification\n"); + result = -ENOMEM; goto out; } INIT_WORK(&nw->work, wa_notif_dispatch); -- 1.9.1