Re: [PATCH 1/3] 2.6.0 aacraid driver update

Matthew Wilcox
2003-10-07T21:39:14Z

On Tue, Oct 07, 2003 at 02:18:12PM -0700, Mark Haverkamp wrote:
> > > - pci_unmap_single(dev->pdev, (dma_addr_t)(ulong)scsicmd->SCp.ptr,
> > > + pci_unmap_single(dev->pdev, (dma_addr_t)(unsigned long)scsicmd->SCp.ptr,
> > > scsicmd->request_bufflen,
> > > scsi_to_pci_dma_dir(scsicmd->sc_data_direction));

> I checked out this casting today. The function takes a dma_addr_t as
> the argument. You can't just pass the pointer in as is because:
>
> drivers/scsi/aacraid/aachba.c:690: warning: passing arg 2 of `pci_unmap_single'
> makes integer from pointer without a cast
>
> If you just cast the pointer to dma_addr_t you get:
>
> drivers/scsi/aacraid/aachba.c:688: warning: cast from pointer to integer of different size
>
> If you just cast to unsigned long, as in the code below, there aren't any warnings, but
> the wrong type is being passed to the function. So, I think that both the casts are
> needed.

Oops, that's not true. Try it out yourself.

int foo(short bar);

int baz(void)
{
return foo(0x12345678);
}

will truncate the argument to foo to 0x5678 before calling it by
implicitly casting to a short. So we can do just fine with:

- pci_unmap_single(dev->pdev, (dma_addr_t)(ulong)scsicmd->SCp.ptr,
+ pci_unmap_single(dev->pdev, (unsigned long)scsicmd->SCp.ptr,
scsicmd->request_bufflen,
scsi_to_pci_dma_dir(scsicmd->sc_data_direction));

Now that all that casting is out of the way, we can see this driver isn't
highmem-safe as it's storing a dma_addr_t in a pointer ... yuck.

--
"It's not Hollywood. War is real, war is primarily not about defeat or
victory, it is about death. I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk