Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp380560pxk; Wed, 2 Sep 2020 04:10:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypPwzxUirbkO+4DGFcnMLlsxxXNCSTcJiUxfLpXPN6FTOWiTcSrw71ZjQgWPsgDytDfHpm X-Received: by 2002:a17:907:2173:: with SMTP id rl19mr5647953ejb.514.1599045057163; Wed, 02 Sep 2020 04:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599045057; cv=none; d=google.com; s=arc-20160816; b=hT3dTLuHSqbR+15D660kT792wm+J7FUiszZ30jWWWy9SSOkE+LE6tckynjKQMs7rSp jYHmdyQqhGdmx+DSnGJhQQDwf49pG1axbuYLPAo0ocZXZZYqKFvC62JSQzdjt9e07sVh bMW29vk5STMOWqaAgsoSzYDJDwyxijZRvvm6/RJ1NFoSh1j9gFh2XbSP4z6fJSJLF0gK umf0QiFlQf3UrpuUYYPsCF8zGzX/nVW4AAeHVseNIXCtjgGf23g3BxbkeXWwKU4fXKTW HOUqXiTCnJt8zmW3r5rhjtcSIV+fkCPFOjOdL7b6bYlVAkviMhJ+HckHL+Wkwfu7K/it QzcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=lRbPBiajhyZAHFvs+KY/rfMq5G+YigmViKEtUETUpvU=; b=qElPjsDuXhrHANOY6pcKsEQrKSRFChQHzg+Bjc6neSG4DB0/Qkapm5LJBpF4Td2HDZ o28ExJPDaF5v5jeeD/wyY7l8q983roqeN5bkov1wFLmrL+oV+XRBQI23lpuGefOcuqxW pHmvI3L+LKZPevKPtRohD50a3C6d7QCXMA66oZzbKfQBtB4VRhpOa6/FgDThAYAJIB7a cPh8r/zCp1uK7UkEFqJG6tPzFVtfwbIDIUvuGiDEiAto6diNVWiOi0ge1QzD/C1V5lXH PZnpoFkpushTOMEp62lYicZeZ4kN+He/yszqb+jMEQ1eA++4Rhi+tvrs9KyVs6zAOuRk TgUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FA9jJNgx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v12si595528ejb.434.2020.09.02.04.10.33; Wed, 02 Sep 2020 04:10:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FA9jJNgx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726674AbgIBLHy (ORCPT + 99 others); Wed, 2 Sep 2020 07:07:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726268AbgIBLHv (ORCPT ); Wed, 2 Sep 2020 07:07:51 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23049C061245 for ; Wed, 2 Sep 2020 04:07:51 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id bh1so2115798plb.12 for ; Wed, 02 Sep 2020 04:07:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lRbPBiajhyZAHFvs+KY/rfMq5G+YigmViKEtUETUpvU=; b=FA9jJNgxjJvc9qlnqShwrPZn3AEONW5P4dh7YWPvhcMQXHUhYKjBtiz3kMOeuGCATx Fy2XOfBQo6n6bix1+nBZec3g6ou+954h1o+5cfOJzwZUNJHfWktY+cMSeDA8TgrPe3YS rHMF0UnGCJcoP9bav+/CLE+5Ymz2ejyJTM0JY= 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:mime-version :content-transfer-encoding; bh=lRbPBiajhyZAHFvs+KY/rfMq5G+YigmViKEtUETUpvU=; b=bWhG8/zRSX/0SlUncrMu5o8czC/gpIm9XNMPLq4WO3Qn9lq4pg5mKl2Za2rviDmgY0 7VH8t5ED/0/pEWcvaYQMi7MhrjkSHgRSVaxaZHHngTT5CltDiLB0ov8x5eNAO9/AvvIg BVtiXXbiW+8W3leiAc5yL+D9ge1FijtW4ADtkV8UuFJQ/Ns/BH8LGdBzalXENb4CbY8z ipe+uOnD/+KJZ0QCcNH01NUlXJxDUWNyQBfYgH13M/xsm2OL5wh54xYOXwBs08jSY5pd odcokkZkGmXQwbbkMo5z/ljsmshQEDECUEKZeM7e0J2ChEbSrb6OWxKLlkUxkYrKeOlq QgJw== X-Gm-Message-State: AOAM532BbdVaDKwIsh2Bdg2/sPEwtKaka/Uh7b3dns43oFA87ln9E7bu twEZYxv24B3ePu/MWS2nYIhj+A== X-Received: by 2002:a17:902:fe91:b029:d0:5d99:c1a2 with SMTP id x17-20020a170902fe91b02900d05d99c1a2mr6013188plm.0.1599044870566; Wed, 02 Sep 2020 04:07:50 -0700 (PDT) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:7220:84ff:fe09:41dc]) by smtp.gmail.com with ESMTPSA id l13sm5523144pgq.33.2020.09.02.04.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 04:07:49 -0700 (PDT) From: Nicolas Boichat To: Bjorn Andersson Cc: Nicolas Boichat , Matthias Brugger , Ohad Ben-Cohen , Pi-Hsun Shih , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-remoteproc@vger.kernel.org Subject: [PATCH v2] rpmsg: Avoid double-free in mtk_rpmsg_register_device Date: Wed, 2 Sep 2020 19:07:15 +0800 Message-Id: <20200902190709.v2.1.I56cf27cd59f4013bd074dc622c8b8248b034a4cc@changeid> X-Mailer: git-send-email 2.28.0.402.g5ffc5be6b7-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If rpmsg_register_device fails, it will call mtk_rpmsg_release_device which already frees mdev. Fixes: 7017996951fde84 ("rpmsg: add rpmsg support for mt8183 SCP.") Signed-off-by: Nicolas Boichat --- Changes in v2: - Drop useless if and ret variable (Markus Elfring) drivers/rpmsg/mtk_rpmsg.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/rpmsg/mtk_rpmsg.c b/drivers/rpmsg/mtk_rpmsg.c index 83f2b8804ee989d..96a17ec2914011d 100644 --- a/drivers/rpmsg/mtk_rpmsg.c +++ b/drivers/rpmsg/mtk_rpmsg.c @@ -200,7 +200,6 @@ static int mtk_rpmsg_register_device(struct mtk_rpmsg_rproc_subdev *mtk_subdev, struct rpmsg_device *rpdev; struct mtk_rpmsg_device *mdev; struct platform_device *pdev = mtk_subdev->pdev; - int ret; mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); if (!mdev) @@ -219,13 +218,7 @@ static int mtk_rpmsg_register_device(struct mtk_rpmsg_rproc_subdev *mtk_subdev, rpdev->dev.parent = &pdev->dev; rpdev->dev.release = mtk_rpmsg_release_device; - ret = rpmsg_register_device(rpdev); - if (ret) { - kfree(mdev); - return ret; - } - - return 0; + return rpmsg_register_device(rpdev); } static void mtk_register_device_work_function(struct work_struct *register_work) -- 2.28.0.402.g5ffc5be6b7-goog