Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp137121pxk; Wed, 2 Sep 2020 17:09:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQgkWlXBXOuwOgr1FtYhBYPEbQzqOe8Sz35ZhD6Nxb55n+jmGW4bKL7SU/SDuGRs5fVPi5 X-Received: by 2002:a05:6402:b1c:: with SMTP id bm28mr406548edb.116.1599091755732; Wed, 02 Sep 2020 17:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599091755; cv=none; d=google.com; s=arc-20160816; b=PIHMEYXWxExDhwJTDcYUoZXa/mCrqSjBa8VTj7nIQm2jt+R9FcgVPWNgyGdz1fjpG1 cbfK0mQ5Ijj5KlTg5vy/AZ9paW2J1TfP0pYmvtbkpJRJzE8HpN/uTFmMVkSxY331uq1N JyfQRf8Rbvp1dPrg980h0QibGVpG8EIRtTAPbwlvaknxYACXZQe20irnvp9qTDe7dFhY 7ZdeMJbNRvucIA6qGXZVfaKzfQnPjQSgxAgQRLqGlmNzItWTRK7xuWQUpT+IMy5trEyo FElsTr4YLeoePssN1waL61Yvhk3tF6qQ21xA4SGk00x5ZLWhV7EXYA1ZqLlUBYwLh0+b SZBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=vNGK0drLoWNgYFtnyo0bGiJC6OE4+o9KPc4VANTcGUU=; b=hkLaGiub5Yrl8sbzXRakmmLKyvPsqBxNlTDNtMlwZDPYK27MqFUGLng5kDxhLl5J/f wL7hHkvcpwnUJSVoZ84p0d+wMW9Y+lmQCnbaknD6lIbGoeUof9pzSergFkMMghlTQzhy nZkZa0GnqwR4R2Dpr1xa7kZBHTQ5Cv8S3j3C1TuF/JTBlrLzUcN1hxHZ5kNM0aMQtRBF YVfRbfD3RjS7ckaq9yk91/0UUP8ukwRWBcBg4Wr5nsWadRhDsN3eZRc7x7BOYmiEY4PD l5lkt9WImhVkUGPLen/61Fjq5CEi3FnUVGitQYfIf/ueAdJwqtaavkVkuvOCZmlehxGn KYuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZVPNUDXf; 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 dk17si752619ejb.71.2020.09.02.17.08.52; Wed, 02 Sep 2020 17:09:15 -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=ZVPNUDXf; 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 S1727792AbgICAIQ (ORCPT + 99 others); Wed, 2 Sep 2020 20:08:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726377AbgICAIN (ORCPT ); Wed, 2 Sep 2020 20:08:13 -0400 Received: from mail-vs1-xe44.google.com (mail-vs1-xe44.google.com [IPv6:2607:f8b0:4864:20::e44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC502C061244 for ; Wed, 2 Sep 2020 17:08:11 -0700 (PDT) Received: by mail-vs1-xe44.google.com with SMTP id b16so722558vsl.6 for ; Wed, 02 Sep 2020 17:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vNGK0drLoWNgYFtnyo0bGiJC6OE4+o9KPc4VANTcGUU=; b=ZVPNUDXf6tQVcgw8kkHHQyjEAOsLqycSIz1ehYZm+uVXTd9CN/j5btk5vfe+0MxcpN z0MpYoLoq3SETJ9XNMrcemRwFcAyZQadJmVdpxOACzSkHQKavJzwtcVAxvf6+bGo337V G47Y0VYQUWmV0mr4nvMqdD/QNGIE9tI4Bw3wQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vNGK0drLoWNgYFtnyo0bGiJC6OE4+o9KPc4VANTcGUU=; b=hAM3ept+API5EbuSzxs09gU3RW/cLf+ItKFs/ZpZYYPFaxEwjKvyi6lc/3kvjA60Jr NAK7T1INMbygS7A85YjRmUVQTYm9jfIe5QYPHTke7XKRxppoBYd7Mvk58GSH4E+ynsgu BLeeXgBNGcyc9gaTSvw8/GyYtgnKtJJXoMSvBYafvIr6VlSgWSZgnrY4W7bEqioLE6mS ApNPW9h15IShkI/fGmkrLDZQ952e7iC5V8qVzdVINMeQgjtKFP1Xo/2DstLaNbZslhks dBZW5br3MmoIHR4+NjCBv7cSiZMCW5Y+H17Rm1cnt05ug8Xp2SkeeX84lUOKgT34fZRh GbLw== X-Gm-Message-State: AOAM532KPOfqk0SSy1goLtZSj4TE0JJU1BDMXJ8Ja/Xgai/bG+7UXGzP oEQAx6LuO8bNuGobuuvG6QIcz+6AHNCwriodR4pevA== X-Received: by 2002:a05:6102:3d7:: with SMTP id n23mr164533vsq.57.1599091690996; Wed, 02 Sep 2020 17:08:10 -0700 (PDT) MIME-Version: 1.0 References: <20200902190709.v2.1.I56cf27cd59f4013bd074dc622c8b8248b034a4cc@changeid> <20200902165505.GA280378@xps15> In-Reply-To: <20200902165505.GA280378@xps15> From: Nicolas Boichat Date: Thu, 3 Sep 2020 08:08:00 +0800 Message-ID: Subject: Re: [PATCH v2] rpmsg: Avoid double-free in mtk_rpmsg_register_device To: Mathieu Poirier Cc: Bjorn Andersson , Matthias Brugger , Ohad Ben-Cohen , Pi-Hsun Shih , linux-arm Mailing List , lkml , "moderated list:ARM/Mediatek SoC support" , "open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 3, 2020 at 12:55 AM Mathieu Poirier wrote: > > On Wed, Sep 02, 2020 at 07:07:15PM +0800, Nicolas Boichat wrote: > > 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.") > > The SHA should be 12 characters instead of 15. With that: Done in v3, thanks (and fixed my process for next time). > Reviewed-by: Mathieu Poirier > > > 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 > >