From patchwork Thu Apr 11 21:17:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13626563 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 6C852C4345F 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=DJYhg9Axkf1msZ+5NYEDR2yp8HNezfABzOIcl1iOnLw=; b=eXRx42dib/tejJ 1FVUMs+L8pAmxk6eDiqY4VKdG8oWYNhUOK310rYaf+Vg3T/imm3kaKiz5kWHDBK2Je9wOv9DKWXn6 hPnYwK7jy+vu8VTHbWTg4TiqpaCD5LeoYafW5h5TGVwN1LzCOMTyJPFqhOt77YsBaxLDjcwREBIRU vGnNS7/ntrDNfXayFsgYYDAGlpC2JMbxxZZfUweVyHaTFbaLCm0Rcx1w5x33FfSK6LuNo9XGXKEoc oVnrXDgmk60OwQxO15Xs0vEYGbkEG2PwgII5vqrLVO8Bfgyi1nExmaGIjHQ8Ur/tkGkoSX95Bwlee TlOFuuIDiP2NvEzeZKYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rv1oT-0000000EA0L-26Hn; Thu, 11 Apr 2024 21:18:29 +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 1rv1o1-0000000E9iY-09hT for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2024 21:18:04 +0000 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-5aa1b7a37b5so178516eaf.2 for ; Thu, 11 Apr 2024 14:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1712870280; x=1713475080; 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=e5nSR1yFGYwMcL96r69NW1l3sh3LFO29KJ2x2ErdnHk=; b=OYJDKvVEelSBCElThvkou6ydXJKp/ha+1YhxsuJfDIWTELt0QW0Fw5a8XBQyCaovGj 7Gb8j4ux+GheIDa6eyRXnKceQc8v/FSqUToVtrTbo/LjkBnY6MZhkBQDUaGwBA1kxSdm 86OMvYKCx/m7U6Dobl24MzxAAm1AqQes+DiMw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712870280; x=1713475080; 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=e5nSR1yFGYwMcL96r69NW1l3sh3LFO29KJ2x2ErdnHk=; b=rXBdCDpFf4NQjy+gHG4RG8/4tlS+Nv/tgZhxS9X/QPF+9HTh5TTHadeXfrOsFD/D1S X0rr3iZMIpC2Cx+sMLUpAB9eq+flq5PQMzX8prcLGjnYuLEJcL5YWPsIGM7cYK/elNZY vYeBRvzVtf5c8nxYJGusyxFi2xHJ5sQOcAzNbI+kEFUEFbwA+rJfKB+JEvds9ThqRlw6 mDefQM0TnBXqN5NK5qXM1Yvdxc9tfZj0benrqWy0kmCtaXwjm8EANcxXwXPdefG3Z8GD FMrtW2UyQ2PqguKwrp8yRKqN7WatlObdvc9xDbagJQlWYzqHQzta9F2eZGsI7blAM/GZ U+WQ== X-Forwarded-Encrypted: i=1; AJvYcCWGtpxh+JJ05zvS8SOFgYf71xOisK0j97hI2xyNBT1rWSDrKsnCiC9saeqe6UVRQBzKJGsyFhQwUq8WzKV9rDiKoMmFZDZEZc72xH5sXho5gNup9Ts= X-Gm-Message-State: AOJu0Yxb5OLOk7J9xORrwSkOc4vEDYLRMpkWYJaJHuSgkVn1NFyCrjDC hWLorSg4AollDzONagDTd8xDf7vXrrWmaZZJNK4zlkOPg2yaQaZivPhhYZYBiw== X-Google-Smtp-Source: AGHT+IEh0blwfOKKlbWUs8oomzyYZwweaLJ6NFxR3Gr9CI9V/VL83VlcnszoDVWX3MZ+lZ28+ZL6Tg== X-Received: by 2002:a05:6358:4b45:b0:186:f3f:3252 with SMTP id ks5-20020a0563584b4500b001860f3f3252mr667180rwc.14.1712870279979; Thu, 11 Apr 2024 14:17:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 14:17:59 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 11 Apr 2024 21:17:55 +0000 Subject: [PATCH 6/7] media: dvb-frontends: drx39xyj: Refactor firmware upload MIME-Version: 1.0 Message-Id: <20240411-fix-smatch-v1-6-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 X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240411_141801_516728_F29B687C X-CRM114-Status: GOOD ( 16.24 ) 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 Do not cache the file, instead load it on demand. This makes smatch a happy parser: drivers/media/dvb-frontends/drx39xyj/drxj.c:11908 drx_ctrl_u_code() warn: 'fw' from request_firmware() not released on lines: 11877,11886,11896. Signed-off-by: Ricardo Ribalda --- drivers/media/dvb-frontends/drx39xyj/drx_driver.h | 2 - drivers/media/dvb-frontends/drx39xyj/drxj.c | 49 +++++++++++------------ 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/drivers/media/dvb-frontends/drx39xyj/drx_driver.h b/drivers/media/dvb-frontends/drx39xyj/drx_driver.h index 15f7e58c5a308..2c2fd4bf79ccf 100644 --- a/drivers/media/dvb-frontends/drx39xyj/drx_driver.h +++ b/drivers/media/dvb-frontends/drx39xyj/drx_driver.h @@ -33,7 +33,6 @@ #include #include -#include #include /* @@ -1910,7 +1909,6 @@ struct drx_demod_instance { /* generic demodulator data */ struct i2c_adapter *i2c; - const struct firmware *firmware; }; /*------------------------------------------------------------------------- diff --git a/drivers/media/dvb-frontends/drx39xyj/drxj.c b/drivers/media/dvb-frontends/drx39xyj/drxj.c index 19d8de400a687..1ef53754bc037 100644 --- a/drivers/media/dvb-frontends/drx39xyj/drxj.c +++ b/drivers/media/dvb-frontends/drx39xyj/drxj.c @@ -56,6 +56,7 @@ INCLUDE FILES #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ #include +#include #include #include #include @@ -11750,6 +11751,7 @@ static int drx_ctrl_u_code(struct drx_demod_instance *demod, u8 *mc_data = NULL; unsigned size; char *mc_file; + const struct firmware *fw; /* Check arguments */ if (!mc_info || !mc_info->mc_file) @@ -11757,28 +11759,22 @@ static int drx_ctrl_u_code(struct drx_demod_instance *demod, mc_file = mc_info->mc_file; - if (!demod->firmware) { - const struct firmware *fw = NULL; - - rc = request_firmware(&fw, mc_file, demod->i2c->dev.parent); - if (rc < 0) { - pr_err("Couldn't read firmware %s\n", mc_file); - return rc; - } - demod->firmware = fw; - - if (demod->firmware->size < 2 * sizeof(u16)) { - rc = -EINVAL; - pr_err("Firmware is too short!\n"); - goto release; - } + rc = request_firmware(&fw, mc_file, demod->i2c->dev.parent); + if (rc < 0) { + pr_err("Couldn't read firmware %s\n", mc_file); + return rc; + } - pr_info("Firmware %s, size %zu\n", - mc_file, demod->firmware->size); + if (fw->size < 2 * sizeof(u16)) { + rc = -EINVAL; + pr_err("Firmware is too short!\n"); + goto release; } - mc_data_init = demod->firmware->data; - size = demod->firmware->size; + pr_info("Firmware %s, size %zu\n", mc_file, fw->size); + + mc_data_init = fw->data; + size = fw->size; mc_data = (void *)mc_data_init; /* Check data */ @@ -11874,7 +11870,8 @@ static int drx_ctrl_u_code(struct drx_demod_instance *demod, 0x0000)) { pr_err("error reading firmware at pos %zd\n", mc_data - mc_data_init); - return -EIO; + rc = -EIO; + goto release; } result = memcmp(curr_ptr, mc_data_buffer, @@ -11883,7 +11880,8 @@ static int drx_ctrl_u_code(struct drx_demod_instance *demod, if (result) { pr_err("error verifying firmware at pos %zd\n", mc_data - mc_data_init); - return -EIO; + rc = -EIO; + goto release; } curr_addr += ((dr_xaddr_t)(bytes_to_comp / 2)); @@ -11893,17 +11891,17 @@ static int drx_ctrl_u_code(struct drx_demod_instance *demod, break; } default: - return -EINVAL; + rc = -EINVAL; + goto release; } mc_data += mc_block_nr_bytes; } - return 0; + rc = 0; release: - release_firmware(demod->firmware); - demod->firmware = NULL; + release_firmware(fw); return rc; } @@ -12271,7 +12269,6 @@ static void drx39xxj_release(struct dvb_frontend *fe) kfree(demod->my_ext_attr); kfree(demod->my_common_attr); kfree(demod->my_i2c_dev_addr); - release_firmware(demod->firmware); kfree(demod); kfree(state); }