[v1,1/6] baseband/fpga_5gnr_fec: fix possible div by zero

Message ID 20230523184818.139353-2-hernan.vargas@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series baseband/fpga_5gnr_fec: changes for 23.07 |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Hernan Vargas May 23, 2023, 6:48 p.m. UTC
  Add fix to have an early exit when z_c is zero to prevent a possible
division by zero.

Fixes: 44dc6faa796f ("baseband/fpga_5gnr_fec: add LDPC processing functions")
Cc: stable@dpdk.org

Signed-off-by: Hernan Vargas <hernan.vargas@intel.com>
---
 drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Maxime Coquelin May 23, 2023, 7:26 p.m. UTC | #1
On 5/23/23 20:48, Hernan Vargas wrote:
> Add fix to have an early exit when z_c is zero to prevent a possible
> division by zero.
> 
> Fixes: 44dc6faa796f ("baseband/fpga_5gnr_fec: add LDPC processing functions")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Hernan Vargas <hernan.vargas@intel.com>
> ---
>   drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c b/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
> index f29565af8cca..9388cce52960 100644
> --- a/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
> +++ b/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
> @@ -879,6 +879,8 @@ get_k0(uint16_t n_cb, uint16_t z_c, uint8_t bg, uint8_t rv_index)
>   {
>   	if (rv_index == 0)
>   		return 0;
> +	if (z_c == 0)
> +		return 0;
>   	uint16_t n = (bg == 1 ? N_ZC_1 : N_ZC_2) * z_c;

You could take the opportunity to move n declaration at the top of the
function.

We this done, feel free to add:
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime


>   	if (n_cb == n) {
>   		if (rv_index == 1)
  

Patch

diff --git a/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c b/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
index f29565af8cca..9388cce52960 100644
--- a/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
+++ b/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
@@ -879,6 +879,8 @@  get_k0(uint16_t n_cb, uint16_t z_c, uint8_t bg, uint8_t rv_index)
 {
 	if (rv_index == 0)
 		return 0;
+	if (z_c == 0)
+		return 0;
 	uint16_t n = (bg == 1 ? N_ZC_1 : N_ZC_2) * z_c;
 	if (n_cb == n) {
 		if (rv_index == 1)