From patchwork Fri Mar 18 17:21:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Conor Dooley X-Patchwork-Id: 12785693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4FFB9C433F5 for ; Fri, 18 Mar 2022 17:23:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=crV0y0Upb+YA471Or/0GYkabGLBKfnkf2dfnuYHgTEs=; b=MGkni06brqlMme R0W8ypIxHveM3I3b1C9vB29Ar6SDxE73Gj5vtdOaqqHZZtS4mW3XM4n1YJySuNlgKgiPwk3JSJtF/ lwxuYN8W6kx9KQ7yqD0+37fEm/NFeb3h7k7EunQePRetuOy8173n8REdw6ks+KgtVz+AxjLGh+rBI FFhQsbLoCx2qaqADPAChsETKeGE86KPhvzZryrZvedOuftjnBq029Ui+JCqAuFJRSCpL1ncL7OoF6 FoYd1OFb/NtJSTxZkRhdLOSyPX5ruDFZger1eI3hUb0KF58libqNpBhCjayU7E5r03nIm1/gNlZKN s0M9BrftoJYX2605LTSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nVGJL-002UDi-QX; Fri, 18 Mar 2022 17:22:47 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nVGJG-002UC6-FP for linux-arm-kernel@lists.infradead.org; Fri, 18 Mar 2022 17:22:44 +0000 Received: by mail-wm1-x333.google.com with SMTP id v2-20020a7bcb42000000b0037b9d960079so7044050wmj.0 for ; Fri, 18 Mar 2022 10:22:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=conchuod-ie.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l9534a34/AgA9Z2/apBy/6pemIM2g3WRkNrlI/px40Y=; b=tXreencTQidCxFJwd7ZQo1jGUzWbf0nCUjUIqXUSF7i3hJfuCQ0V7CPqRWjm+Nuz50 /qavkdFCiypMZP72TOcIbMqOZJMQTktJtIZKZ7ZmoTae5kkCRyYfJsNeI9mZ29DJb/hR roQd1SU9ozXdiB3m6/VFzVjdGz/7ZktT6T6KdW+9rgtxwH7zhNXqEKbICUfutKAOurhy DfV3NbmdDkUuBjfB+Kwjs7unJCbdh2zLFV7E5MqXT/fUTP7LqdjG5TtDbjshPpKP4TG+ Vw2GYiMzgUoJsbR7f0v48T2vEIvdoOuB1T3pcBB3T/pSyhezrtFdt2jt67I18t3BgArX 3u9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l9534a34/AgA9Z2/apBy/6pemIM2g3WRkNrlI/px40Y=; b=AL7Ndci5jQGEmgotzJQoOx42BBLAB0eme3Xa9N29QD3/ig5NEmE7TdWo6vwePAZ1x/ DR/peQtNxtF0H3Tf9Gc9zPotqFVoreN4S8rDu+zQbD06egUMCTdZTSHug6VHoeR7kI8E ee8BtX0FtOoDGJQLC4A2w9R8hPALMDzMmqOEm+kN372zo+oCkK9yon6pnx+ljehkjukd RlhEyYa/8AhBYqx0EBatUTcDogXhZKfa4UOl4joKvpRk0mn0Y64KpsmZHUTMu49YcLlg RX+jtLMhTbFcptZ65ixBAnQT+B02Vfzt2z3yQsQtO1P+07SpIBCioXIfhXHySkPcDwZS BqEA== X-Gm-Message-State: AOAM533Gpj5fTMMHptlUD/4ZzTnn2juDJ25dITLqwER9fAN+BBTXhXIH HMIein/4UqLNuMKSqUpJdBntYQ== X-Google-Smtp-Source: ABdhPJyDh+usVz8Tot9VRPesh6vbKBHRpScfPgpbIJG9Ob8LkCUY+dHJCAsexSYsHfP04rSLP8rHQw== X-Received: by 2002:a1c:7517:0:b0:38c:8722:9bc6 with SMTP id o23-20020a1c7517000000b0038c87229bc6mr4644093wmc.2.1647624160384; Fri, 18 Mar 2022 10:22:40 -0700 (PDT) Received: from spud.. ([109.76.4.19]) by smtp.gmail.com with ESMTPSA id r13-20020adfbb0d000000b00203e0efdd3bsm6556874wrg.107.2022.03.18.10.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Mar 2022 10:22:39 -0700 (PDT) From: Conor Dooley To: nicolas.ferre@microchip.com, arnd@arndb.de Cc: olof@lixom.net, conor.dooley@microchip.com, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kernel test robot , Conor Dooley Subject: [PATCH] soc/microchip: fix invalid free in mpfs_sys_controller_delete Date: Fri, 18 Mar 2022 17:21:08 +0000 Message-Id: <20220318172107.1599399-1-mail@conchuod.ie> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220318_102242_525183_6E5801B0 X-CRM114-Status: GOOD ( 14.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Conor Dooley Fix an invalid kfree in mpfs_sys_controller_delete, by replacing the devm_kzalloc with a regular kzalloc. Change the error handling in the probe function to free the sys_controller struct if the probe fails. > cocci warnings: (new ones prefixed by >>) > >> drivers/soc/microchip/mpfs-sys-controller.c:73:1-6: WARNING: invalid free of devm_ allocated data Link: https://lore.kernel.org/linux-mm/202203180259.lgIylRZV-lkp@intel.com/ Fixes: d0054a470c33 ("soc: add microchip polarfire soc system controller") Reported-by: kernel test robot Signed-off-by: Conor Dooley Signed-off-by: Conor Dooley --- drivers/soc/microchip/mpfs-sys-controller.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/microchip/mpfs-sys-controller.c index 31f3f29fc1ae..6e20207b5756 100644 --- a/drivers/soc/microchip/mpfs-sys-controller.c +++ b/drivers/soc/microchip/mpfs-sys-controller.c @@ -95,9 +95,9 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct mpfs_sys_controller *sys_controller; - int i; + int i, ret; - sys_controller = devm_kzalloc(dev, sizeof(*sys_controller), GFP_KERNEL); + sys_controller = kzalloc(sizeof(*sys_controller), GFP_KERNEL); if (!sys_controller) return -ENOMEM; @@ -106,9 +106,12 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev) sys_controller->client.tx_block = 1U; sys_controller->chan = mbox_request_channel(&sys_controller->client, 0); - if (IS_ERR(sys_controller->chan)) - return dev_err_probe(dev, PTR_ERR(sys_controller->chan), - "Failed to get mbox channel\n"); + if (IS_ERR(sys_controller->chan)) { + ret = dev_err_probe(dev, PTR_ERR(sys_controller->chan), + "Failed to get mbox channel\n"); + kfree(sys_controller); + return ret; + } init_completion(&sys_controller->c); kref_init(&sys_controller->consumers);