HilscherAutomation / nxdrvlinux

cifX device driver for linux.
https://www.hilscher.com
GNU General Public License v2.0
13 stars 3 forks source link

Bug in libcifx/cifxlinux.c:565 - ‘ulSize’ undeclared for printf("DMA buffer %d found at 0x%p / size=%d\n", device->dma_buffer_cnt, membase, ulSize); #8

Closed juwalter closed 1 month ago

juwalter commented 1 month ago

in https://github.com/HilscherAutomation/nxdrvlinux/blob/main/libcifx/cifxlinux.c#L565 when enabling VERBOSE, this code does not compile

for(;(device->dma_buffer_cnt < CIFX_DMA_BUFFER_COUNT) && (currfile < num_map); ++currfile)
    {
      if (CIFX_NO_ERROR == validate_memtype( device->uio_num, currfile, eMEM_DMA))
      {
        void *membase = NULL;
        unsigned long memaddr;
        unsigned long memlen;
        if (cifx_uio_map_mem(device->uio_fd, device->uio_num,
                     currfile, &membase,
                     &memaddr,
                     &memlen,
                     0))
        {
          int DMACounter = 0;
          if ((DMACounter = memlen/(CIFX_DEFAULT_DMA_BUFFER_SIZE)))
          {
            while(DMACounter)
            {
              device->dma_buffer[device->dma_buffer_cnt].ulSize            = CIFX_DEFAULT_DMA_BUFFER_SIZE;
              device->dma_buffer[device->dma_buffer_cnt].ulPhysicalAddress = memaddr;
              device->dma_buffer[device->dma_buffer_cnt].pvBuffer          = membase;
              device->dma_buffer_cnt++;
              memaddr += CIFX_DEFAULT_DMA_BUFFER_SIZE;
              membase += CIFX_DEFAULT_DMA_BUFFER_SIZE;
#ifdef VERBOSE
              printf("DMA buffer %d found at 0x%p / size=%d\n", device->dma_buffer_cnt, membase, ulSize);
#endif
              DMACounter--;
            }
          }

should this line

#ifdef VERBOSE
              printf("DMA buffer %d found at 0x%p / size=%d\n", device->dma_buffer_cnt, membase, ulSize);
#endif

use CIFX_DEFAULT_DMA_BUFFER_SIZE instead of undeclared ulSize?

#ifdef VERBOSE
              printf("DMA buffer %d found at 0x%p / size=%d\n", device->dma_buffer_cnt, membase, CIFX_DEFAULT_DMA_BUFFER_SIZE);
#endif
MTrensch-hilscher commented 1 month ago

Thanks for the catch, it seems to be a relict from former times, when variable DMA buffer sizes were being used. As we are seldomly using VERBOSE mode, it seems like it slipped through.

As the buffers are all CIFX_DEFAULT_DMA_BUFFER_SIZE now, this should be save to use.

juwalter commented 1 month ago

thank you @MTrensch-hilscher