From patchwork Thu Oct 17 19:40:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13840761 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 98943D3C52C for ; Thu, 17 Oct 2024 19:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=QZpms9R5kWODAqigQeGsxMS1uylrcIOwy5W+fcCCNgo=; b=z/WeccByxYqtaKhm0gVhPjSO9C g1QFmMaeEggBhaplePEccCNkusGKoZpl9wXfPupZexc0XjxkP5k1Ef7BdI/XIGyAUTCwDGf3bIPp1 9WZgyj/1Jt9enTCl5F6zSZ16WCDJEu4kKPMk/41aqugBhon9qSu6ttERUJRJsCQQQZRLdSk4rsyA4 Frb2vHq5A4Wv9O32w1hqLBbO4tFyTlPTHrH5f3LedyKuKwMbtjhB8zcqfyvP18sfaUF6+4zdEZ475 AeWfRkbaO4s2o+t8kNdvtaZzney1VieMdTsQhONVaOOQQWXIQ8dg15F5rqKgrwVEsS4dWC2er5IYc t2fVyEOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1WNZ-0000000G3Rk-0CZb; Thu, 17 Oct 2024 19:41:49 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1WM1-0000000G3Bj-3Mi3 for linux-arm-kernel@lists.infradead.org; Thu, 17 Oct 2024 19:40:18 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a99eb8b607aso135791566b.2 for ; Thu, 17 Oct 2024 12:40:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729194011; x=1729798811; darn=lists.infradead.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=QZpms9R5kWODAqigQeGsxMS1uylrcIOwy5W+fcCCNgo=; b=SNmlXuW14WgRNbIZvPo6TiOWo70nmbw1d9D9SR/qySUTVY9cOV/ul16O1XnW3vlve0 DqYCvfFej9AaRiE+9bY6EEAcp0Rn5JgQsxXsGhVBDFpOY+rQI/Hy0f6W1gEbwkRTWn4p zKj8WOv2zwTsnv1KQavdrhNyB+wk62H06sbIgRFO32ko4SjjJQZzXcUC0ong8p7dc3We Rsdt44rVqAzh1UZ/yC7RA9rz5oac/jX05JvEjxI6pWFjJaQGpKjsYEjuPN0wjpvgc2UL UY1QBe183dAwzFU5mQ4NZ7IYJktmxyU80uHpj95P2CJ/5S7S/fWRqgfzUwUjEZC2QMTi EUtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729194011; x=1729798811; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QZpms9R5kWODAqigQeGsxMS1uylrcIOwy5W+fcCCNgo=; b=QhKKDDhKw1IEkzL8heDzUx/zPyfJINktJhInLmya3oOzRVo+MWsCWtRDQi20YPgOx7 xeL36qlixmgnQxBVG0iFM78jOE+q5VkhYezSgWQS66rcA7aksDnzJQORMAEYKyefNvGJ Ra/86Yp7lkLKbVIp940tbiMiiGtjlJSF6c9dSAZm/4b2CIJYyLSyMxEJEcfwK2ovcjBD 7qu+AU/aWpURhgMP1KJAAKHQxaznXHxWIn+At7mezmgtxW4DElSwS93Fo25kFJHZ7Mqt dNUvqJnYDuMiGNWGGjcqJn+wamcvjUGW0OLvibau0TvV9k2L9rulvnfCN+abGYBiF2u+ 0UeA== X-Forwarded-Encrypted: i=1; AJvYcCV4PFqnvKsvftT7RPKVlWUWI1nMs+GoNtdvOCxMIFfTrX0k48iFgwnNVc9doVviRa8Kn4A2BO1/8cf/nvyGzzWL@lists.infradead.org X-Gm-Message-State: AOJu0YyROabxPZ1tz6qZBNDp9eMq3dNgMzb6VoTG6RuHfvBDOVsKCl9b gG+W2j0s8oX4qpXkikT0hsu8gEBtEGq/EF+pd6RDQwnr/5xgqw1x/hQyKE9kOeQ= X-Google-Smtp-Source: AGHT+IGxstbOFapOUqQjp3ZRs6n1QMqDvHLOM3P/WHoCxTXHHg04lmOTKj0g3pfWvKqi+rO1wTNiWw== X-Received: by 2002:a17:906:bc23:b0:a99:368d:dad3 with SMTP id a640c23a62f3a-a9a34d078d5mr696337266b.30.1729194011492; Thu, 17 Oct 2024 12:40:11 -0700 (PDT) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a68bf7037sm2959166b.183.2024.10.17.12.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 12:40:10 -0700 (PDT) Date: Thu, 17 Oct 2024 22:40:05 +0300 From: Dan Carpenter To: Ming Qian Cc: Mirela Rabulea , Mauro Carvalho Chehab , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Hans Verkuil , TaoJiang , imx@lists.linux.dev, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH next] media: imx-jpeg: Fix potential error pointer dereference in detach_pm() Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241017_124013_983745_EC91F241 X-CRM114-Status: GOOD ( 12.87 ) 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 The proble is on the first line: if (jpeg->pd_dev[i] && !pm_runtime_suspended(jpeg->pd_dev[i])) If jpeg->pd_dev[i] is an error pointer, then passing it to pm_runtime_suspended() will lead to an Oops. The other conditions check for both error pointers and NULL, but it would be more clear to use the IS_ERR_OR_NULL() check for that. Fixes: fd0af4cd35da ("media: imx-jpeg: Ensure power suppliers be suspended before detach them") Signed-off-by: Dan Carpenter --- drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c index d8e946aebba2..918ab12edc9e 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c @@ -2679,11 +2679,12 @@ static void mxc_jpeg_detach_pm_domains(struct mxc_jpeg_dev *jpeg) int i; for (i = 0; i < jpeg->num_domains; i++) { - if (jpeg->pd_dev[i] && !pm_runtime_suspended(jpeg->pd_dev[i])) + if (!IS_ERR_OR_NULL(jpeg->pd_dev[i]) && + !pm_runtime_suspended(jpeg->pd_dev[i])) pm_runtime_force_suspend(jpeg->pd_dev[i]); - if (jpeg->pd_link[i] && !IS_ERR(jpeg->pd_link[i])) + if (!IS_ERR_OR_NULL(jpeg->pd_link[i])) device_link_del(jpeg->pd_link[i]); - if (jpeg->pd_dev[i] && !IS_ERR(jpeg->pd_dev[i])) + if (!IS_ERR_OR_NULL(jpeg->pd_dev[i])) dev_pm_domain_detach(jpeg->pd_dev[i], true); jpeg->pd_dev[i] = NULL; jpeg->pd_link[i] = NULL;