Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp284837imm; Tue, 21 Aug 2018 19:45:38 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwEkyg53kjqo7fZK8f/ltN+3R2PfI6HH/YJkWQoM9/KWm43DNDM1RJLk6ZB9W/JjyYBK6Jt X-Received: by 2002:a62:d44e:: with SMTP id u14-v6mr24154566pfl.258.1534905938039; Tue, 21 Aug 2018 19:45:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534905938; cv=none; d=google.com; s=arc-20160816; b=TtQI0gcJx0YSkhiuXqQQo7Zf4wglk9QVtcFWR//Y4Z6Q5EEvzm3qUl1i+l+ibICc2K TOk0tjZxnQY/pheK29uNXRad2ZJku/86AUEeslzNlFuD/1C7zcKl2Sv3GaQ+UWCWRumw FEGg8hX/sTn+CrL65G6KbFfuTqeWWrwK/YB1xTuIxr2UI9tVu+npopS9Ko9LXYk58zzm pm/cT4ODO92eUwwq0CGcErHK7lJzTLWGd6Hj3sSOnKpdRNav50C3TjvhGL4Gx6evH7MP huvvEK+4sD58RGtXvLTMy0Ms4jtSN1ajbo4bVsIOGbUko9vGKHi7tE8gpDKu9AsYwkoo Y6uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=9HjC0pSE0Dk8Qpfpry/Fg/8ppzap3yvWYx5/B7623i0=; b=vH5fdKKv34Q3dWttXTkEKZGQBMQ/CcNePzDsygJatDVlUtcBCuowBeM9FDF8HATgb1 z1x3m36K60gDhYSZHwzcTNaIINfS4eFdflAs+2S2SFs0mfHs/jKxO0wta1j3WII/Ss8+ Gi+Ar8t1nbg/ynZ8zTp4XxGtVWyJu+a6AE5qcv0gutrFoQouRhvQJsZu/SLvT1WMqtfq SAHKQ17x5OHOJaA16fBwd1FklAeeAqWXU8kRALM/EfFjSc145qw2Vp13NnEpVeFn9Fa8 0PQWWSAzMVXRbUkkuPZnBqQMhgDZrvtyP0VTguFk2O/i+i3LJec4/GYy+iwCQdQfC51B d7eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@iluvatar.ai header.s=809B2F8E-810B-11E8-86FD-A0A654EEFFEB header.b="BSe/QtU5"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=iluvatar.ai Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g6-v6si482658pgq.240.2018.08.21.19.45.08; Tue, 21 Aug 2018 19:45:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@iluvatar.ai header.s=809B2F8E-810B-11E8-86FD-A0A654EEFFEB header.b="BSe/QtU5"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=iluvatar.ai Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbeHVGDc (ORCPT + 99 others); Wed, 22 Aug 2018 02:03:32 -0400 Received: from mail.iluvatar.ai ([58.213.90.100]:54966 "EHLO mail.iluvatar.ai" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726469AbeHVGDc (ORCPT ); Wed, 22 Aug 2018 02:03:32 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.iluvatar.ai (Postfix) with ESMTP id 5B9961070E175; Wed, 22 Aug 2018 10:44:20 +0800 (CST) Received: from mail.iluvatar.ai ([127.0.0.1]) by localhost (mail.iluvatar.ai [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id HrZgkAZqropz; Wed, 22 Aug 2018 10:44:19 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by mail.iluvatar.ai (Postfix) with ESMTP id C9E501070725D; Wed, 22 Aug 2018 10:44:19 +0800 (CST) DKIM-Filter: OpenDKIM Filter v2.9.2 mail.iluvatar.ai C9E501070725D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iluvatar.ai; s=809B2F8E-810B-11E8-86FD-A0A654EEFFEB; t=1534905859; bh=9HjC0pSE0Dk8Qpfpry/Fg/8ppzap3yvWYx5/B7623i0=; h=From:To:Subject:Date:Message-Id; b=BSe/QtU5habbXCIfh1y6Wl6J20l38jlSCG+hhSo+RkOpc4v5NSdVMIEH/3i4uiGhZ M0XyMzs3fnq/P/3/XzTU4NhciVDo19ijxF/Sx2r2t2S8U7mGASbSqjnEgGhfm1xx1w 0ScJbHLUowec/pRyUEA8NoiGrMqMz8C1xvwLYask= X-Virus-Scanned: amavisd-new at iluvatar.ai Received: from mail.iluvatar.ai ([127.0.0.1]) by localhost (mail.iluvatar.ai [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id wCiMhM-WNFeV; Wed, 22 Aug 2018 10:44:19 +0800 (CST) Received: from localhost.localdomain (unknown [180.166.124.10]) by mail.iluvatar.ai (Postfix) with ESMTPSA id 850961070219A; Wed, 22 Aug 2018 10:44:19 +0800 (CST) From: Huang Shijie To: vkoul@kernel.org Cc: sudeep.dutt@intel.com, ashutosh.dixit@intel.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, Huang Shijie Subject: [PATCH v2] dma: mic_x100_dma: use devm_kzalloc to fix an issue Date: Wed, 22 Aug 2018 10:40:27 +0800 Message-Id: <20180822024027.8984-1-sjhuang@iluvatar.ai> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following patch introduced an issue. commit f6206f00d8c5 ("dmaengine: mic_x100_dma: use the new helper to simplify the code") This issue is : kfree(mic_dma_dev) ..... dma_async_device_unregister(mic_dma_dev->device); Free the memory, and use it again. So use devm_kzalloc to allocate mic_dma_dev to fix it. When the Devres try to release the resources, it will call release at the following order: dma_async_device_unregister(mic_dma_dev->device); ..... kfree(mic_dma_dev) Fixes: f6206f00d8c5 ("dmaengine: mic_x100_dma: use the new helper to simplify the code") Signed-off-by: Huang Shijie --- v1 --> v2: Change the commit message and title --- drivers/dma/mic_x100_dma.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/dma/mic_x100_dma.c b/drivers/dma/mic_x100_dma.c index b76cb17d879c..adfd316db1a8 100644 --- a/drivers/dma/mic_x100_dma.c +++ b/drivers/dma/mic_x100_dma.c @@ -639,7 +639,7 @@ static struct mic_dma_device *mic_dma_dev_reg(struct mbus_device *mbdev, int ret; struct device *dev = &mbdev->dev; - mic_dma_dev = kzalloc(sizeof(*mic_dma_dev), GFP_KERNEL); + mic_dma_dev = devm_kzalloc(dev, sizeof(*mic_dma_dev), GFP_KERNEL); if (!mic_dma_dev) { ret = -ENOMEM; goto alloc_error; @@ -664,7 +664,6 @@ static struct mic_dma_device *mic_dma_dev_reg(struct mbus_device *mbdev, reg_error: mic_dma_uninit(mic_dma_dev); init_error: - kfree(mic_dma_dev); mic_dma_dev = NULL; alloc_error: dev_err(dev, "Error at %s %d ret=%d\n", __func__, __LINE__, ret); @@ -674,7 +673,6 @@ static struct mic_dma_device *mic_dma_dev_reg(struct mbus_device *mbdev, static void mic_dma_dev_unreg(struct mic_dma_device *mic_dma_dev) { mic_dma_uninit(mic_dma_dev); - kfree(mic_dma_dev); } /* DEBUGFS CODE */ -- 2.17.1