From patchwork Thu Apr 11 21:17:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13626564 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 C9F03C00A94 for ; Thu, 11 Apr 2024 21:18:41 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MulleSb3pYUvUT4fqK4fl8sh3rqfyYpn+53DRy2Uq50=; b=ECoGDEpRcIiZcq PL1YvM7N0dyJLA0DZynmM+7veh0BeIahBE2zMqNp5t0tdmxQFe6hvRNA0zaOh/YstzpcMPzLWsyJx PhlsCE+W0hleikPFi768wyCnWosPLXNb1RPCEkn2yxbyCxQegVd/MpzFS0hYsvDFMVR64MfK35lrc 5ChLDyKuaKl7M1SrYP4YsuHIOSvn8L+7fe9hn+ws7WK7g1OKJv28iMVtmG0RNkwzG5rsezlWiHIf7 benySLgxTH/2dX6snmziMFzZBIu6LMs2ZObYxKUunNtWszxLaExdHTvX7LVomD7te7kYGhIg/iptk Rgh83QPMw0qb+sBwOtsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rv1oP-0000000E9wf-35B2; Thu, 11 Apr 2024 21:18:25 +0000 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rv1nz-0000000E9gd-3aFn for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2024 21:18:03 +0000 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-5aa12c21ff4so183008eaf.3 for ; Thu, 11 Apr 2024 14:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1712870278; x=1713475078; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7uKL1mHSZL4YF4kY3BJqD6MsU90syv43Ru49OzukfDM=; b=ce9Dl1UD81Z0SozWCP/fuEs/D+57GcwJRyXiNbSbLLRzAnYq0MF97hu4ZBJ/FdKFoo Mma0ZwGfQ7mWW6aVdFZJbSAj9gm+/SH6LRCZGT2w8Mx4iQ6uyB2w4pCg9emLZgysNtvm CDlvPyXF+Lu2k6wni+KF7dB/K/QeVy5GKGMTo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712870278; x=1713475078; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7uKL1mHSZL4YF4kY3BJqD6MsU90syv43Ru49OzukfDM=; b=OjGsehCGosQto9vs2Vl2nVcnQH+kFaB1FGSJUx1HpI1F2vI7Hs6qiwhtZmCvG5Df2i iigNStSyert4EwCQC+CapBTK4GWPjrGDP3MK4Wefb/OSZzALbZ/6xjIUGoKImmoSQX5E 99NLnuhURB/7Kn9Z9Yl//OmaaGjUVuVgyLWTtwhsqpFJGvaEeB6GxTAnipy8WjdsPbDj zihJav6Ts8OSP8fMJH8EkYHxQyQUxuME1+Y5OnlN3JJR0AF0lP9LW3KEkNoHwwiEMtif 4/IQ5o2jifcCyax3Xar8z/1dVHvqPT/FwhoRBSz8rIzRAD+lZwHws0DvFmkLmWPIPhVp n0Vg== X-Forwarded-Encrypted: i=1; AJvYcCWbgb+po4zR0suEGdFcrp0KdrZzHo2drMiqZVnKKU1xzVuX3gPJvPnDV5fvmu//0b5rEfRxM9YnulzNpX7hA29DuvqsgzYbutbmsTrb7Uy0NA1N4DU= X-Gm-Message-State: AOJu0Yyy8WweYMwMJ2poUWYWIRrC+DrtO2EihHNCdwDkGNBWVKLJyhE3 nbpyHS/t62z1JqpdjX5dWH7jBz+3KOE3VRy12fqKAilKp1oOhoCCp4YWLak2mQ== X-Google-Smtp-Source: AGHT+IGhlN9obDs811TzuFeTw+yQpMZFy0dDvN3jgb99c2lssw4pJXubU4SOxjWfkOF/RoOypkxSZg== X-Received: by 2002:a05:6358:9807:b0:186:12cb:d1a8 with SMTP id y7-20020a056358980700b0018612cbd1a8mr629894rwa.25.1712870278344; Thu, 11 Apr 2024 14:17:58 -0700 (PDT) Received: from denia.c.googlers.com (200.234.86.34.bc.googleusercontent.com. [34.86.234.200]) by smtp.gmail.com with ESMTPSA id k20-20020ac84794000000b00434d7c4f9fasm1373362qtq.8.2024.04.11.14.17.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 14:17:58 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 11 Apr 2024 21:17:54 +0000 Subject: [PATCH 5/7] media: tunner: xc5000: Refactor firmware load MIME-Version: 1.0 Message-Id: <20240411-fix-smatch-v1-5-045f92467937@chromium.org> References: <20240411-fix-smatch-v1-0-045f92467937@chromium.org> In-Reply-To: <20240411-fix-smatch-v1-0-045f92467937@chromium.org> To: Bluecherry Maintainers , Anton Sviridenko , Andrey Utkin , Ismael Luceno , Mauro Carvalho Chehab , Patrice Chotard Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ricardo Ribalda , Shuah Khan X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240411_141800_042340_B99C1CEE X-CRM114-Status: GOOD ( 16.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 Make sure the firmware is released when we leave xc_load_fw_and_init_tuner() This change makes smatch happy: drivers/media/tuners/xc5000.c:1213 xc_load_fw_and_init_tuner() warn: 'fw' from request_firmware() not released on lines: 1213. Cc: Shuah Khan Signed-off-by: Ricardo Ribalda --- drivers/media/tuners/xc5000.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c index 2182e5b7b6064..30aa4ee958bde 100644 --- a/drivers/media/tuners/xc5000.c +++ b/drivers/media/tuners/xc5000.c @@ -58,7 +58,7 @@ struct xc5000_priv { struct dvb_frontend *fe; struct delayed_work timer_sleep; - const struct firmware *firmware; + bool inited; }; /* Misc Defines */ @@ -1110,23 +1110,19 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force) if (!force && xc5000_is_firmware_loaded(fe) == 0) return 0; - if (!priv->firmware) { - ret = request_firmware(&fw, desired_fw->name, - priv->i2c_props.adap->dev.parent); - if (ret) { - pr_err("xc5000: Upload failed. rc %d\n", ret); - return ret; - } - dprintk(1, "firmware read %zu bytes.\n", fw->size); + ret = request_firmware(&fw, desired_fw->name, + priv->i2c_props.adap->dev.parent); + if (ret) { + pr_err("xc5000: Upload failed. rc %d\n", ret); + return ret; + } + dprintk(1, "firmware read %zu bytes.\n", fw->size); - if (fw->size != desired_fw->size) { - pr_err("xc5000: Firmware file with incorrect size\n"); - release_firmware(fw); - return -EINVAL; - } - priv->firmware = fw; - } else - fw = priv->firmware; + if (fw->size != desired_fw->size) { + pr_err("xc5000: Firmware file with incorrect size\n"); + release_firmware(fw); + return -EINVAL; + } /* Try up to 5 times to load firmware */ for (i = 0; i < 5; i++) { @@ -1204,6 +1200,7 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force) } err: + release_firmware(fw); if (!ret) printk(KERN_INFO "xc5000: Firmware %s loaded and running.\n", desired_fw->name); @@ -1274,7 +1271,7 @@ static int xc5000_resume(struct dvb_frontend *fe) /* suspended before firmware is loaded. Avoid firmware load in resume path. */ - if (!priv->firmware) + if (!priv->inited) return 0; return xc5000_set_params(fe); @@ -1293,6 +1290,8 @@ static int xc5000_init(struct dvb_frontend *fe) if (debug) xc_debug_dump(priv); + priv->inited = true; + return 0; } @@ -1306,10 +1305,6 @@ static void xc5000_release(struct dvb_frontend *fe) if (priv) { cancel_delayed_work(&priv->timer_sleep); - if (priv->firmware) { - release_firmware(priv->firmware); - priv->firmware = NULL; - } hybrid_tuner_release_state(priv); }