From patchwork Wed Nov 28 14:39:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 152291 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1170644ljp; Wed, 28 Nov 2018 06:40:15 -0800 (PST) X-Google-Smtp-Source: AFSGD/XVrqc4/NCrOCRPd+aWDBEb87MDlNHmpyiEWTe1gGl0knrCGl992gbpN0yhxuVInS2HuH7R X-Received: by 2002:a17:902:720c:: with SMTP id ba12mr20609631plb.79.1543416015539; Wed, 28 Nov 2018 06:40:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543416015; cv=none; d=google.com; s=arc-20160816; b=qEfx0Fo6trbmmSJMfYzybtzPDoUVl7mtIecMqMSDJs9uXBTsB8bk2DrxmCOtCoOyli AQcjUN/qKnlzvC69uNDgmEGAqcOVI5wfK7+/WgPHmlW35qR5FXRmuZ139VT0FVNTHKTV itlAYDrtUj7a7meNkuhkMkm8Zf0pq2eczarEHS0++F1y1MsW0XNclghaVVkmZ2DqWfdp yTJKpQnNgDPRzL84AoeW0anbWvuihoKFwXWDG+rEcfy87zcuQNUHzNIsUeLWMDePa0PD lCQ8etpXHGzoqNFABl3R7Mfym459KgxSn8vmrz/7ccbvRz2iODwM0Bp0OPSGoGknFkTu 7UnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=OGjSNWuO6l6Vxy8LWCp2CNqpjJkIapuX5+++9+NLUr8=; b=qwCeCtwvzQ1cbDSD1QDapjQB8m5R6EQSuVWix+al5NMe+SjMUz2QvG9juhw+UNgNGu vRIKQNfkhO/442kjdZ/TPnWCmXPFKZ1I86PslF6NgI/6q5xea0zgIbfithW+sKRhAK+x sYOttZnNeyb/LwXaB6HjPIQbIIFYrZ4rGl32xwXjzS7c07Dls3dJ784lzmKTeHJLrlLl 4byHUqbsolLXn0NlbDwH+FxTG9zhPQlUQPbjyieOe+3xKIKj2U1Iu81dKySKGYUNXEpt 9RSAzmCzpdFVozkBCWTegbgKXqG+/3DMG9bKpD4uOOTHj4d9LiDkGoIZOE20yWXwrKGF roug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eLyHcJAJ; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i67si5274274pfc.148.2018.11.28.06.40.15; Wed, 28 Nov 2018 06:40:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eLyHcJAJ; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728372AbeK2BmH (ORCPT + 15 others); Wed, 28 Nov 2018 20:42:07 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:41260 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728342AbeK2BmH (ORCPT ); Wed, 28 Nov 2018 20:42:07 -0500 Received: by mail-pl1-f194.google.com with SMTP id u6so17480856plm.8 for ; Wed, 28 Nov 2018 06:40:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OGjSNWuO6l6Vxy8LWCp2CNqpjJkIapuX5+++9+NLUr8=; b=eLyHcJAJJIVAA2AOQxUG+k+LQ8ftr5t8wl0Iwn/4hrNESJTY4IFPbiyJt5JhwWX4xg HD/LfQY+n7hn6bijvz4AnD5pR8nGnMI6Kt3rO5P9qYN3iwg0TIcnaGf7D2K8xPByjawY kZrOJu/LC47M19fTVOdSKA0RxcAgZzsLDQUJU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OGjSNWuO6l6Vxy8LWCp2CNqpjJkIapuX5+++9+NLUr8=; b=G2aW6oJn3Jdu6+ItwoOiIPpDiHRc9tz7VPMySVshBg/7YxfiYQj44brMYUdHISwHfi MdaaqLNzBcMWkFWzfnsykdYrGVnCr3gwKVfQcl4un5Qa6IW2A+t3Jx57wkHpiHsgy4Ek 5qNH+bMA/xVBfagROo6mT8XXJFw8JSM/ucR+Xz0s9O6U9uzmYMxIKJopSV6KCZUyCo/f Y4RTr3YLIUvHXw9zZkSjORtLWOz1pyGkiTLBYJDvYu7+EL19JFhzBVRr7Giw/B85kxmu HF7Jg15zQM0X3MG1335RK58Kn+/GiuzvZiA+WnLZ4mWMEHFaV5FbEmN+zUmDD9pZW9lK w0lQ== X-Gm-Message-State: AA+aEWb0gSAdTYiyhUWFTvpXaXlrSxe07BUDAVNsDAAefzeC0UKvpZbW FWOpYHqNRT9wnkHY7gAOWjW9uw== X-Received: by 2002:a17:902:5066:: with SMTP id f35mr33317644plh.78.1543416013594; Wed, 28 Nov 2018 06:40:13 -0800 (PST) Received: from localhost.localdomain ([49.207.53.6]) by smtp.gmail.com with ESMTPSA id b26sm24227637pfe.91.2018.11.28.06.40.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Nov 2018 06:40:12 -0800 (PST) From: Amit Pundir To: Greg KH Cc: Stable , Johannes Thumshirn , Johannes Berg , Kalle Valo Subject: [PATCH for-4.9.y 02/10] cw1200: Don't leak memory if krealloc failes Date: Wed, 28 Nov 2018 20:09:56 +0530 Message-Id: <1543416004-1547-3-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543416004-1547-1-git-send-email-amit.pundir@linaro.org> References: <1543416004-1547-1-git-send-email-amit.pundir@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Johannes Thumshirn commit 9afdd6128c39f42398041bb2e017d8df0dcebcd1 upstream. The call to krealloc() in wsm_buf_reserve() directly assigns the newly returned memory to buf->begin. This is all fine except when krealloc() failes we loose the ability to free the old memory pointed to by buf->begin. If we just create a temporary variable to assign memory to and assign the memory to it we can mitigate the memory leak. Signed-off-by: Johannes Thumshirn Cc: Johannes Berg Signed-off-by: Kalle Valo Signed-off-by: Amit Pundir --- drivers/net/wireless/st/cw1200/wsm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) -- 2.7.4 diff --git a/drivers/net/wireless/st/cw1200/wsm.c b/drivers/net/wireless/st/cw1200/wsm.c index ed93bf3474ec..be4c22e0d902 100644 --- a/drivers/net/wireless/st/cw1200/wsm.c +++ b/drivers/net/wireless/st/cw1200/wsm.c @@ -1805,16 +1805,18 @@ static int wsm_buf_reserve(struct wsm_buf *buf, size_t extra_size) { size_t pos = buf->data - buf->begin; size_t size = pos + extra_size; + u8 *tmp; size = round_up(size, FWLOAD_BLOCK_SIZE); - buf->begin = krealloc(buf->begin, size, GFP_KERNEL | GFP_DMA); - if (buf->begin) { - buf->data = &buf->begin[pos]; - buf->end = &buf->begin[size]; - return 0; - } else { - buf->end = buf->data = buf->begin; + tmp = krealloc(buf->begin, size, GFP_KERNEL | GFP_DMA); + if (!tmp) { + wsm_buf_deinit(buf); return -ENOMEM; } + + buf->begin = tmp; + buf->data = &buf->begin[pos]; + buf->end = &buf->begin[size]; + return 0; }