Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2806776pxb; Fri, 12 Feb 2021 01:35:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnZ/fOD6+g2eI4jqSJUyZCu6+2XiiKTZjU7b4030RBOd1GdOszY13dFlPmn5IhdhA1o/iy X-Received: by 2002:aa7:c407:: with SMTP id j7mr2413366edq.28.1613122518647; Fri, 12 Feb 2021 01:35:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613122518; cv=none; d=google.com; s=arc-20160816; b=Gfk8ozg2+BCoaShSl7juEzmtxeu+WDR0RKDqq9zH2ew/BKxysaOMbDgDVZD/mft7cQ ugNucK2TU1AtvLPzmYoWxbuIIKlcGY5rbYuopNgLiX3BagufUXFpmgJyjUWZEWR9tF2r GGFPeTAQlx68uAoYbE8WFxYxHr+wA7hNy0oZALFe+hvH1OEA2T3AI42rrM5RpuH+ths6 W0NZdJnDL5jLg9uGEIpF63YGZw4nrFHrZ/chJngLIIXztkCiwB+T+/6MejcSv4Lq3UPv MiMQ/YPF8qpHzNJaEr2thOGto/0TVQNEML9XcZp5gal30V/P20pqdFP3Ml/2YhGyNZSG +H/w== 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=L185B0n/p/YV0S/8Ph/0c9gY8dABJQerX1apqQ5i9jI=; b=I6moQG1NEXsnQCheTeepuqXZJDmLPKXH2sE3IQ/nBO6X2r5nZnLcAhj6hgCOcATEQp kR9KqWtQY1GaPTJw1VQ3Xr9GyeuoiZO1w6nn+WGH1GNEVUfcxQM0OzPOfjTm8L5SM330 JugEkazlWTk8Y0dNaDC35szBdesQzXBsIp5sN+Uxu3j6WmrGolspS3tk4Frr0TYiA3Nh Yd4Kr11rdfB+BB/dZkVYbovXCTB/hoo30SKUWpxQZ+2ty1VNCXmNPxZ1ABLQdhv061za tJPOCOyVLYO5WYFZZ0YIRNPFUX4oRHcXjGaLDjeA7te/tGfc5bMUKpiWpd1fOmXZxHlz tOoA== 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 g20si5558587edb.494.2021.02.12.01.34.53; Fri, 12 Feb 2021 01:35:18 -0800 (PST) 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 S229889AbhBLJbe (ORCPT + 99 others); Fri, 12 Feb 2021 04:31:34 -0500 Received: from mx2.suse.de ([195.135.220.15]:60342 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbhBLJbd (ORCPT ); Fri, 12 Feb 2021 04:31:33 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 89542B141; Fri, 12 Feb 2021 09:30:16 +0000 (UTC) From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Jens Axboe , Christoph Hellwig , Keith Busch , Daniel Wagner , Hannes Reinecke Subject: [PATCH] nvme/hwmon: Return error code when registration fails Date: Fri, 12 Feb 2021 10:30:15 +0100 Message-Id: <20210212093015.2846-1-dwagner@suse.de> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The hwmon pointer wont be NULL if the registration fails. Though the exit code path will assign it to ctrl->hwmon_device. Later nvme_hwmon_exit() will try to free the invalid pointer. Avoid this by returning the error code from hwmon_device_register_with_info(). Fixes: ec420cdcfab4 ("nvme/hwmon: rework to avoid devm allocation") Cc: Hannes Reinecke Signed-off-by: Daniel Wagner --- This patch is against linux-block/for-next. drivers/nvme/host/hwmon.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/nvme/host/hwmon.c b/drivers/nvme/host/hwmon.c index 8f9e96986780..0a586d712920 100644 --- a/drivers/nvme/host/hwmon.c +++ b/drivers/nvme/host/hwmon.c @@ -248,6 +248,7 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl) if (IS_ERR(hwmon)) { dev_warn(dev, "Failed to instantiate hwmon device\n"); kfree(data); + return PTR_ERR(hwmon); } ctrl->hwmon_device = hwmon; return 0; -- 2.29.2