Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752448AbcLDFtZ (ORCPT ); Sun, 4 Dec 2016 00:49:25 -0500 Received: from m50-133.163.com ([123.125.50.133]:60783 "EHLO m50-133.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750778AbcLDFtY (ORCPT ); Sun, 4 Dec 2016 00:49:24 -0500 From: Pan Bian To: Yishai Hadas , Doug Ledford , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] infiniband: hw: mlx4: fix improper return value Date: Sun, 4 Dec 2016 13:49:04 +0800 Message-Id: <1480830544-5002-1-git-send-email-bianpan201603@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DdGowAAXCplPrkNYKKmUIw--.36542S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrKF4ktrWUXr47XrWkAry8AFb_yoWDZrg_WF Wvvrn7ur1rAF93Cr1Fgr9xur92q3Wjgwn7ZwnxKw13A3sxtws8Z392qrn8Zr47XryxCrZx Cr9ava4rGF45CjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUYdcTDUUUUU== X-Originating-IP: [114.243.30.33] X-CM-SenderInfo: held01tdqsiiqwqtqiywtou0bp/xtbBXhI291aDoyJVYQAAst Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1002 Lines: 30 From: Pan Bian If uhw->inlen is non-zero, the value of variable err is 0 if the copy succeeds. Then, if kzalloc() or kmalloc() returns a NULL pointer, it will return 0 to the callers. As a result, the callers cannot detect the errors. This patch fixes the bug, assigning "-ENOMEM" to err before the NULL pointer checks. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189031 Signed-off-by: Pan Bian --- drivers/infiniband/hw/mlx4/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index b597e82..f6c5158 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -455,6 +455,7 @@ static int mlx4_ib_query_device(struct ib_device *ibdev, sizeof(resp.response_length); in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL); out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); + err = -ENOMEM; if (!in_mad || !out_mad) goto out; -- 1.9.1