Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6038878pxv; Thu, 29 Jul 2021 05:05:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkFc4cx/ktSlEAbjr8fApPbz9P5WNpCzPgvdWFLXNRlwhwhWNuEw2i0Vp6egktQb0eAKcP X-Received: by 2002:a02:a797:: with SMTP id e23mr4229030jaj.121.1627560346179; Thu, 29 Jul 2021 05:05:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627560346; cv=none; d=google.com; s=arc-20160816; b=wrY3zsoWS8ahYV/j/OqUBlLqNvTzrjQhPBRNic1M7UpgnABEDTLy/DAXeMsj2hSiCK y3lapCXZMANxW1NAH2r0OyRNjSn9hal88QMG4GIp4UVxguBRwHt38DBoMgftBH08auOa LVrijoVzlWBX7Gr8c+71P5NksMvbXs55WA96By3pN2GNPnjZL1oeSUG25MlpF0UO7ctN hR/FWkYb6FjOUHRq9pL/w1Mpqq0tNRXomUqvpMUz7BJARaC8xwpuNoGmFNy7qSBrqEky A6rKkRHTAiYHcesuRksuH+1aaNpmvCvNIpdDhE47VkLu7aSnQQOFAteRY/lEBm8q+AeX B9KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=0uY13YIDIyDcQdAoH++Ru44809qb8hSZ0rTO/ws7QU8=; b=oIicMk3TTWlMTx9MCX9joZZSTOmNdlocqkwnug6JUY7oz9kKXUtxkvYi8lBd8cs/fR k2KUMTfiqp340O+qbrCtzeFjwaDvZCsQmQsN0F/bXC0dEx/OQJPv32qYdFpFUhxofH/g zVkk3IvnGG30LYXYcaPYd6H+VBoRvHDG7Q1vvJeNqVc9cH1G5c+HfG2YlUFsYE+CF2lh 4o1K3BmjOQ+P8CHGk7L3N7wsN/zrRPxjqjM27K5ZpCY8nyGSFkWpTWz+CfHIivt2BjMM QGrxnIZHJkTW6Q4lLHRhPgDEfuhIe1FdAh8N2ixqAzb+8xbR7K7GLGruqxLACwtxSWzD eWjw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si3161016ioc.54.2021.07.29.05.05.34; Thu, 29 Jul 2021 05:05:46 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234231AbhG2MEP (ORCPT + 99 others); Thu, 29 Jul 2021 08:04:15 -0400 Received: from smtp03.smtpout.orange.fr ([80.12.242.125]:22467 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234737AbhG2MEK (ORCPT ); Thu, 29 Jul 2021 08:04:10 -0400 Received: from localhost.localdomain ([86.243.172.93]) by mwinf5d05 with ME id b0432500421Fzsu03043Zp; Thu, 29 Jul 2021 14:04:06 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Thu, 29 Jul 2021 14:04:06 +0200 X-ME-IP: 86.243.172.93 From: Christophe JAILLET To: dave.jiang@intel.com, vkoul@kernel.org, dan.j.williams@intel.com Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] dmaengine: idxd: Fix a possible NULL pointer dereference Date: Thu, 29 Jul 2021 14:04:01 +0200 Message-Id: <77f0dc4f3966591d1f0cffb614a94085f8895a85.1627560174.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'device_driver_attach()' dereferences its first argument (i.e. 'alt_drv') so it must not be NULL. Simplify the error handling logic about NULL 'alt_drv' in order to be more robust and future-proof. Fixes: 568b2126466f ("dmaengine: idxd: fix uninit var for alt_drv") Fixes: 6e7f3ee97bbe ("dmaengine: idxd: move dsa_drv support to compatible mode") Signed-off-by: Christophe JAILLET --- drivers/dma/idxd/compat.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/dma/idxd/compat.c b/drivers/dma/idxd/compat.c index d7616c240dcd..3df21615f888 100644 --- a/drivers/dma/idxd/compat.c +++ b/drivers/dma/idxd/compat.c @@ -45,23 +45,16 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf, size_t cou idxd_dev = confdev_to_idxd_dev(dev); if (is_idxd_dev(idxd_dev)) { alt_drv = driver_find("idxd", bus); - if (!alt_drv) - return -ENODEV; } else if (is_idxd_wq_dev(idxd_dev)) { struct idxd_wq *wq = confdev_to_wq(dev); - if (is_idxd_wq_kernel(wq)) { + if (is_idxd_wq_kernel(wq)) alt_drv = driver_find("dmaengine", bus); - if (!alt_drv) - return -ENODEV; - } else if (is_idxd_wq_user(wq)) { + else if (is_idxd_wq_user(wq)) alt_drv = driver_find("user", bus); - if (!alt_drv) - return -ENODEV; - } else { - return -ENODEV; - } } + if (!alt_drv) + return -ENODEV; rc = device_driver_attach(alt_drv, dev); if (rc < 0) -- 2.30.2