From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 722141C26 for ; Wed, 23 Nov 2022 09:01:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECCBDC433D6; Wed, 23 Nov 2022 09:01:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1669194075; bh=+ZiLR+3ZeLEPV0rgQYHksJTRzxDgYIBOlFg/wJaz8fM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lx4jf50bInDNL5glkc45K8afucGi01T/GdMoTJ4kkzUWTmvogjdwFxCo9dywGmsfy xGjbmdKPNb7QWFJ6VzdYRG66h3x6XwKo9EoBSHg2cBDnyAUvGlBjfotdqGDctttXNi YfSHpUg9HBNv8gQZCILDGTApeYt8YEw0lUyhZz7Y= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yang Yingliang , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.14 65/88] iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger() Date: Wed, 23 Nov 2022 09:51:02 +0100 Message-Id: <20221123084550.871938911@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221123084548.535439312@linuxfoundation.org> References: <20221123084548.535439312@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Yang Yingliang commit 65f20301607d07ee279b0804d11a05a62a6c1a1c upstream. If iio_trigger_register() returns error, it should call iio_trigger_free() to give up the reference that hold in iio_trigger_alloc(), so that it can call iio_trig_release() to free memory when the refcount hit to 0. Fixes: 0e589d5fb317 ("ARM: AT91: IIO: Add AT91 ADC driver.") Signed-off-by: Yang Yingliang Link: https://lore.kernel.org/r/20221024084511.815096-1-yangyingliang@huawei.com Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/at91_adc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c @@ -618,8 +618,10 @@ static struct iio_trigger *at91_adc_allo trig->ops = &at91_adc_trigger_ops; ret = iio_trigger_register(trig); - if (ret) + if (ret) { + iio_trigger_free(trig); return NULL; + } return trig; }