Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1448413lqb; Sun, 26 May 2024 01:10:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWjr2AeZ45tsGPYH0jLROeUL668jknLQ0FxPKRfLKYvX5bIHaPFU3kr2bWQUmHKSD/X91aLXENAfHUOMDnjhe0wZYbIuQxbDOR06DylZg== X-Google-Smtp-Source: AGHT+IHqR19Kv1IcJnjblyVWpYBtPd/UhGbPr8IAc3efAil4ccFT2pYfma4/ogzl0FW7kHHMH6Yz X-Received: by 2002:a17:902:da8d:b0:1f3:35d9:432b with SMTP id d9443c01a7336-1f4486bd0f3mr66481995ad.10.1716711002751; Sun, 26 May 2024 01:10:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716711002; cv=pass; d=google.com; s=arc-20160816; b=0qB7cgR+joqYOtdUbGCLs6fbPDRmG1OPqT0KTIsCH2q97E5npQyimzfjsA4kQX48P8 k2CjuXuIWYfNONpmZf8SP1gw2xvrFgSveY44hQvqLaM87NQtq9II2wdqh8xfewi3+Wso Xc4jykV1frWTH3WPbIJxjUldYeJlBNtgo6AlSgIARjHFPs/wgffpAErPwNCXZA0M9MKA DvBFyikMU9gjdmFL2fhCWQBfnLNc0ewdDsQRxlANyz1ibiMSHEy2ylI/87xC70y/a6Ca EmjqvU2yEL3FvwdAq5aYx/Xx91hsYrzfGAAryEDaSYwci3qxbb5PmpRN4NeitygSqqWI PVGw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=IgEDtJfaNI1iWwOQr1DJGweCIYES2brPtEIEBcUvbBo=; fh=YW5smIVMRLpbWnLRjvhSpU8t4PLD0BKjznNUr9wl3Ng=; b=djSFqEEdNf4/jkb5cNuSuPHzYcQCPGtDkm5xN1ybTpTX+TvswEDAMq5Konz0uTtrJg XpXspLufJwHPbchVayRfXTCu6tjEZ0S8e8rM/ckYjt/5jmAJGMoEPdWjQJZ+KkGUh66Z p909m6LcVpgkLZN4L/pJ6zYqIg1GDqjPEBZ/aUjPBpIxLDiROYBUu6yCtVOqWvkuMaDl pd1cBCRKuM5m3Al94dZUqNkUFvLHhHaIKGwnk//NNcTEjRPJxjtKFyTFxXZ1ebgh0+zq LppzT4qyvK8z71E/AgY774c4pXAey0mS05HKkf5J+KmZ2R6qbpKKiLY1ut08fKJCz/1l p0Ig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=dD1rjx9l; arc=pass (i=1 spf=pass spfdomain=wanadoo.fr dkim=pass dkdomain=wanadoo.fr dmarc=pass fromdomain=wanadoo.fr); spf=pass (google.com: domain of linux-kernel+bounces-189604-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189604-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c9ac2fesi39678245ad.423.2024.05.26.01.10.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 01:10:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189604-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=dD1rjx9l; arc=pass (i=1 spf=pass spfdomain=wanadoo.fr dkim=pass dkdomain=wanadoo.fr dmarc=pass fromdomain=wanadoo.fr); spf=pass (google.com: domain of linux-kernel+bounces-189604-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189604-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3BBE02813E7 for ; Sun, 26 May 2024 08:10:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5D668F66; Sun, 26 May 2024 08:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="dD1rjx9l" Received: from msa.smtpout.orange.fr (smtp-70.smtpout.orange.fr [80.12.242.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91FEEB640; Sun, 26 May 2024 08:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.70 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716710989; cv=none; b=g0oJvFsP+WV24rPORFJ9Z43l1ymmP0e+pq8wNjKPmCJI27R10mQ8dT2nBvH0h5YH/el12U0EMJ47BM1J1BIMG/QQ9HsLeqOr08otPS/dnQlQT89w+Rd+vD6YcRgGupGL+FSlJBpSGWCqoncssoNeee6SxhMo7DpuGG17d9KRwkY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716710989; c=relaxed/simple; bh=9mL+pOz+vQ8U+AQZywT6y8vUmRELxvG7EkDXJCpb10o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VfFgSbWQ+0haeD3PmV6hDEzh90pBNClJ6iZEoKydWL1qIe7y1ORiLvc9uZ//vDSzmbKPAfLF/NhMJv+vaSex4QmYsJ5rf7XkyILKmbstwaMMWdd2hMH6mcBmPOASAMp/2JXhR5mvS3oHSNXR+g6Ed/Ddk5CDimcClMSR9N7A35I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=dD1rjx9l; arc=none smtp.client-ip=80.12.242.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Received: from fedora.home ([86.243.17.157]) by smtp.orange.fr with ESMTPA id B8nVshp7epUD1B8nhsPLd9; Sun, 26 May 2024 10:00:40 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1716710440; bh=IgEDtJfaNI1iWwOQr1DJGweCIYES2brPtEIEBcUvbBo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=dD1rjx9ljJHof3mvVsNUW2GUHVNARNQhhWGp1hXRBDkHehpCp1jhIZu0E4bjSmKRB no1GajJcY9WORHZrhH3FxT00XWc/BiSnN+2qqPJDG6ZHNAgzO2dwgGcQX/SjyRzZ0O bvDDh/33CFFYaoCuHgD/NxUGB+yKq+8LnrDaHCwEDX/AkFIyypYzBc0qLUFNFPR//M cyJuYerH9/S76t6nCeTDTKNDalA8GLpvPZWQuhDl2mcLIQhYlm7BSJs07Pg3I06q4g khoWa2KHH/oQDupulLNCIg/uOdbop9ERh8koekQy6MOi3AFw8dHgFs7GWal5JQUW26 Fdb+A4EkRYUOw== X-ME-Helo: fedora.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 26 May 2024 10:00:40 +0200 X-ME-IP: 86.243.17.157 From: Christophe JAILLET To: sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, mchehab@kernel.org, hverkuil-cisco@xs4all.nl, hdegoede@redhat.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH v2 2/2] media: intel/ipu6: Fix an error handling path in isys_probe() Date: Sun, 26 May 2024 09:59:57 +0200 Message-ID: <69c6a062959077414af05c44116e2351b0600977.1716710255.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.45.1 In-Reply-To: <15a056198775689cb533a7b0ea7e100559a2465d.1716710255.git.christophe.jaillet@wanadoo.fr> References: <15a056198775689cb533a7b0ea7e100559a2465d.1716710255.git.christophe.jaillet@wanadoo.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If an error occurs after a successful alloc_fw_msg_bufs() call, some resources should be released as already done in the remove function. Add a new free_fw_msg_bufs() function that releases what has been allocated by alloc_fw_msg_bufs(). Also use this new function in isys_remove() to avoid some code duplication. Fixes: f50c4ca0a820 ("media: intel/ipu6: add the main input system driver") Signed-off-by: Christophe JAILLET --- Compile tested only. I'm slightly puzzled by the use of the _safe version of list_for_each_entry(). Is it really needed here. Also, should isys->listlock be used? The code looks racy to me. Changes in v2: - Introduce and use free_fw_msg_bufs() [Sakari Ailus] v1: https://lore.kernel.org/all/545315bcaac0a897c25cfa20a603be2af2a40aa9.1716201136.git.christophe.jaillet@wanadoo.fr/ --- drivers/media/pci/intel/ipu6/ipu6-isys.c | 27 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys.c b/drivers/media/pci/intel/ipu6/ipu6-isys.c index 7ce2047a09b5..1998b72ac07d 100644 --- a/drivers/media/pci/intel/ipu6/ipu6-isys.c +++ b/drivers/media/pci/intel/ipu6/ipu6-isys.c @@ -925,6 +925,20 @@ static const struct dev_pm_ops isys_pm_ops = { .resume = isys_resume, }; +static void free_fw_msg_bufs(struct ipu6_isys *isys) +{ + struct device *dev = &isys->adev->auxdev.dev; + struct isys_fw_msgs *fwmsg, *safe; + + list_for_each_entry_safe(fwmsg, safe, &isys->framebuflist, head) + dma_free_attrs(dev, sizeof(struct isys_fw_msgs), fwmsg, + fwmsg->dma_addr, 0); + + list_for_each_entry_safe(fwmsg, safe, &isys->framebuflist_fw, head) + dma_free_attrs(dev, sizeof(struct isys_fw_msgs), fwmsg, + fwmsg->dma_addr, 0); +} + static int alloc_fw_msg_bufs(struct ipu6_isys *isys, int amount) { struct device *dev = &isys->adev->auxdev.dev; @@ -1105,12 +1119,14 @@ static int isys_probe(struct auxiliary_device *auxdev, ret = isys_register_devices(isys); if (ret) - goto out_remove_pkg_dir_shared_buffer; + goto free_fw_msg_bufs; ipu6_mmu_hw_cleanup(adev->mmu); return 0; +free_fw_msg_bufs: + free_fw_msg_bufs(isys); out_remove_pkg_dir_shared_buffer: if (!isp->secure_mode) ipu6_cpd_free_pkg_dir(adev); @@ -1137,16 +1153,9 @@ static void isys_remove(struct auxiliary_device *auxdev) struct ipu6_bus_device *adev = auxdev_to_adev(auxdev); struct ipu6_isys *isys = dev_get_drvdata(&auxdev->dev); struct ipu6_device *isp = adev->isp; - struct isys_fw_msgs *fwmsg, *safe; unsigned int i; - list_for_each_entry_safe(fwmsg, safe, &isys->framebuflist, head) - dma_free_attrs(&auxdev->dev, sizeof(struct isys_fw_msgs), - fwmsg, fwmsg->dma_addr, 0); - - list_for_each_entry_safe(fwmsg, safe, &isys->framebuflist_fw, head) - dma_free_attrs(&auxdev->dev, sizeof(struct isys_fw_msgs), - fwmsg, fwmsg->dma_addr, 0); + free_fw_msg_bufs(isys); isys_unregister_devices(isys); isys_notifier_cleanup(isys); -- 2.45.1