Skip to content

Commit

Permalink
check that pin and device parameters are positives.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdelnero committed Nov 14, 2023
1 parent e9860a6 commit 5ddf029
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
8 changes: 4 additions & 4 deletions lib_jtag_core/src/bus_over_jtag/i2c_over_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ int jtagcore_i2c_set_scl_pin(jtag_core * jc, int device, int pin)
{
jtag_bsdl * bsdl_file;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0)
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if (pin < bsdl_file->number_of_pins)
if (pin < bsdl_file->number_of_pins && pin >= 0)
{
jc->i2c_scl_pin = pin;
jc->i2c_scl_device = device;
Expand All @@ -74,13 +74,13 @@ int jtagcore_i2c_set_sda_pin(jtag_core * jc, int device, int pin)
{
jtag_bsdl * bsdl_file;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0)
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if (pin < bsdl_file->number_of_pins)
if (pin < bsdl_file->number_of_pins && pin >= 0)
{
jc->i2c_sda_pin = pin;
jc->i2c_sda_device = device;
Expand Down
8 changes: 4 additions & 4 deletions lib_jtag_core/src/bus_over_jtag/mdio_over_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ int jtagcore_mdio_set_mdc_pin(jtag_core * jc, int device, int pin)
{
jtag_bsdl * bsdl_file;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0)
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if (pin < bsdl_file->number_of_pins)
if (pin < bsdl_file->number_of_pins && pin >= 0)
{
jc->mdio_mdc_pin = pin;
jc->mdio_mdc_device = device;
Expand All @@ -66,13 +66,13 @@ int jtagcore_mdio_set_mdio_pin(jtag_core * jc, int device, int pin)
{
jtag_bsdl * bsdl_file;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >=0)
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if (pin < bsdl_file->number_of_pins)
if (pin < bsdl_file->number_of_pins && pin >= 0)
{
jc->mdio_mdio_pin = pin;
jc->mdio_mdio_device = device;
Expand Down
12 changes: 6 additions & 6 deletions lib_jtag_core/src/bus_over_jtag/memory_over_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ int jtagcore_memory_set_address_pin(jtag_core * jc, int address_bit, int device,
{
jtag_bsdl * bsdl_file;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && address_bit < MAX_BUS_WIDTH)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 && address_bit < MAX_BUS_WIDTH)
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if ( pin < bsdl_file->number_of_pins )
if ( pin < bsdl_file->number_of_pins && pin >= 0 )
{
jc->ram_address_pin[address_bit] = pin;
jc->ram_address_device[address_bit] = device;
Expand All @@ -88,13 +88,13 @@ int jtagcore_memory_set_data_pin(jtag_core * jc, int data_bit, int device, int p
{
jtag_bsdl * bsdl_file;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && data_bit < MAX_BUS_WIDTH)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 && data_bit < MAX_BUS_WIDTH)
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if ( pin < bsdl_file->number_of_pins )
if ( pin < bsdl_file->number_of_pins && pin >= 0 )
{
jc->ram_data_pin[data_bit] = pin;
jc->ram_data_device[data_bit] = device;
Expand All @@ -110,13 +110,13 @@ int jtagcore_memory_set_ctrl_pin(jtag_core * jc, int ctrl, int polarity, int dev
{
jtag_bsdl * bsdl_file;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && ctrl < 16)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 && ctrl < 16)
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if ( pin < bsdl_file->number_of_pins )
if ( pin < bsdl_file->number_of_pins && pin >= 0 )
{
jc->ram_ctrl_pin[ctrl] = pin;
jc->ram_ctrl_pin_pol[ctrl] = polarity;
Expand Down
19 changes: 9 additions & 10 deletions lib_jtag_core/src/bus_over_jtag/spi_over_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ int jtagcore_spi_set_mosi_pin(jtag_core * jc, int device, int pin, int sample_cl
{
jtag_bsdl * bsdl_file;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0)
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if (pin < bsdl_file->number_of_pins)
if (pin < bsdl_file->number_of_pins && pin >= 0)
{
jc->spi_mosi_pin = pin;
if(sample_clk_phase)
Expand All @@ -70,13 +70,13 @@ int jtagcore_spi_set_miso_pin(jtag_core * jc, int device, int pin, int sample_cl
{
jtag_bsdl * bsdl_file;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0)
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if (pin < bsdl_file->number_of_pins)
if (pin < bsdl_file->number_of_pins && pin >= 0)
{
jc->spi_miso_pin = pin;
if(sample_clk_phase)
Expand All @@ -96,13 +96,13 @@ int jtagcore_spi_set_clk_pin(jtag_core * jc, int device, int pin, int polarity)
{
jtag_bsdl * bsdl_file;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0)
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if (pin < bsdl_file->number_of_pins)
if (pin < bsdl_file->number_of_pins && pin >= 0)
{
jc->spi_clk_pin = pin;
if(polarity)
Expand All @@ -122,13 +122,13 @@ int jtagcore_spi_set_cs_pin(jtag_core * jc, int device, int pin, int polarity)
{
jtag_bsdl * bsdl_file;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0)
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if (pin < bsdl_file->number_of_pins)
if (pin < bsdl_file->number_of_pins && pin >= 0)
{
jc->spi_cs_pin = pin;
if(polarity)
Expand Down Expand Up @@ -283,9 +283,8 @@ int jtagcore_spi_write_read(jtag_core * jc, int wr_size,unsigned char * wr_buffe

jtagcore_push_and_pop_chain(jc, JTAG_CORE_WRITE_ONLY);

return JTAG_CORE_NO_ERROR;
return JTAG_CORE_NO_ERROR;
}

return JTAG_CORE_BAD_PARAMETER;

}

0 comments on commit 5ddf029

Please sign in to comment.