Commit 840e7ba3 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] tpam annotations and cleanups

annotated, sanitized casts between pointers and numbers, switched the
functions that took offsets in card memory to unsigned long (from the
void *, which was absolutely wrong and lead to bogus casts from hell all
over the place).
Signed-off-by: default avatarAl Viro <viro@parcelfarce.linux.theplanet.co.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 2ad2225a
......@@ -77,7 +77,7 @@ typedef struct tpam_channel {
typedef struct tpam_card {
struct tpam_card *next; /* next card in list */
unsigned int irq; /* IRQ used by this board */
unsigned long bar0; /* ioremapped bar0 */
void __iomem *bar0; /* ioremapped bar0 */
int id; /* id of the board */
isdn_if interface; /* isdn link-level pointer */
int channels_used; /* number of channels actually used */
......@@ -171,12 +171,12 @@ extern tpam_card *tpam_findcard(int);
extern u32 tpam_findchannel(tpam_card *, u32);
/* Function prototypes from tpam_memory.c */
extern void copy_to_pam_dword(tpam_card *, const void *, u32);
extern void copy_to_pam(tpam_card *, void *, const void *, u32);
extern u32 copy_from_pam_dword(tpam_card *, const void *);
extern void copy_from_pam(tpam_card *, void *, const void *, u32);
extern int copy_from_pam_to_user(tpam_card *, void __user *, const void *, u32);
extern int copy_from_user_to_pam(tpam_card *, void *, const void __user *, u32);
extern void copy_to_pam_dword(tpam_card *, u32, u32);
extern void copy_to_pam(tpam_card *, u32, const void *, u32);
extern u32 copy_from_pam_dword(tpam_card *, u32);
extern void copy_from_pam(tpam_card *, void *, u32, u32);
extern int copy_from_pam_to_user(tpam_card *, void __user *, u32, u32);
extern int copy_from_user_to_pam(tpam_card *, u32, const void __user *, u32);
extern int tpam_verify_area(u32, u32);
/* Function prototypes from tpam_nco.c */
......
......@@ -21,8 +21,8 @@
#include "tpam.h"
/* Local functions prototypes */
static int tpam_command_ioctl_dspload(tpam_card *, u32);
static int tpam_command_ioctl_dspsave(tpam_card *, u32);
static int tpam_command_ioctl_dspload(tpam_card *, unsigned long);
static int tpam_command_ioctl_dspsave(tpam_card *, unsigned long);
static int tpam_command_ioctl_dsprun(tpam_card *);
static int tpam_command_ioctl_loopmode(tpam_card *, u8);
static int tpam_command_dial(tpam_card *, u32, u8 *);
......@@ -114,7 +114,7 @@ int tpam_command(isdn_ctrl *c) {
*
* Return: 0 if OK, <0 on errors.
*/
static int tpam_command_ioctl_dspload(tpam_card *card, u32 arg) {
static int tpam_command_ioctl_dspload(tpam_card *card, unsigned long arg) {
tpam_dsp_ioctl tdl;
pr_debug("TurboPAM(tpam_command_ioctl_dspload): card=%d\n", card->id);
......@@ -130,7 +130,7 @@ static int tpam_command_ioctl_dspload(tpam_card *card, u32 arg) {
return -EPERM;
/* write the data in the board's memory */
return copy_from_user_to_pam(card, (void *)tdl.address,
return copy_from_user_to_pam(card, tdl.address,
(void __user *)arg + sizeof(tpam_dsp_ioctl),
tdl.data_len);
}
......@@ -144,7 +144,7 @@ static int tpam_command_ioctl_dspload(tpam_card *card, u32 arg) {
*
* Return: 0 if OK, <0 on errors.
*/
static int tpam_command_ioctl_dspsave(tpam_card *card, u32 arg) {
static int tpam_command_ioctl_dspsave(tpam_card *card, unsigned long arg) {
tpam_dsp_ioctl tdl;
pr_debug("TurboPAM(tpam_command_ioctl_dspsave): card=%d\n", card->id);
......@@ -159,7 +159,7 @@ static int tpam_command_ioctl_dspsave(tpam_card *card, u32 arg) {
/* read the data from the board's memory */
return copy_from_pam_to_user(card, (void __user *)arg + sizeof(tpam_dsp_ioctl),
(void *)tdl.address, tdl.data_len);
tdl.address, tdl.data_len);
}
/*
......@@ -186,7 +186,7 @@ static int tpam_command_ioctl_dsprun(tpam_card *card) {
/* reset the board */
spin_lock_irq(&card->lock);
copy_to_pam_dword(card, (void *)TPAM_MAGICNUMBER_REGISTER, 0xdeadface);
copy_to_pam_dword(card, TPAM_MAGICNUMBER_REGISTER, 0xdeadface);
readl(card->bar0 + TPAM_DSPINT_REGISTER);
readl(card->bar0 + TPAM_HINTACK_REGISTER);
spin_unlock_irq(&card->lock);
......@@ -196,7 +196,7 @@ static int tpam_command_ioctl_dsprun(tpam_card *card) {
while (time_before(jiffies, timeout)) {
spin_lock_irq(&card->lock);
signature = copy_from_pam_dword(card,
(void *)TPAM_MAGICNUMBER_REGISTER);
TPAM_MAGICNUMBER_REGISTER);
spin_unlock_irq(&card->lock);
if (signature == TPAM_MAGICNUMBER)
break;
......@@ -531,14 +531,14 @@ int tpam_writebuf_skb(int driverId, int channel, int ack, struct sk_buff *skb) {
if (!(tempdata = (void *)__get_free_page(GFP_ATOMIC))) {
printk(KERN_ERR "TurboPAM(tpam_writebuf_skb): "
"get_free_page failed\n");
free_page((u32)finaldata);
free_page((unsigned long)finaldata);
return -ENOMEM;
}
hdlc_no_accm_encode(skb->data, skb->len, tempdata, &templen);
finallen = tpam_hdlc_encode(tempdata, finaldata,
&card->channels[channel].hdlcshift,
templen);
free_page((u32)tempdata);
free_page((unsigned long)tempdata);
}
/* free the old sk_buff */
......@@ -548,13 +548,13 @@ int tpam_writebuf_skb(int driverId, int channel, int ack, struct sk_buff *skb) {
skb = build_U3DataReq(card->channels[channel].ncoid, finaldata,
finallen, ack, orig_size);
if (!skb) {
free_page((u32)finaldata);
free_page((unsigned long)finaldata);
return -ENOMEM;
}
tpam_enqueue_data(&card->channels[channel], skb);
/* free the temporary memory */
free_page((u32)finaldata);
free_page((unsigned long)finaldata);
return orig_size;
}
......@@ -865,11 +865,11 @@ void tpam_recv_U3DataInd(tpam_card *card, struct sk_buff *skb) {
if (!(result = alloc_skb(templen, GFP_ATOMIC))) {
printk(KERN_ERR "TurboPAM(tpam_recv_U3DataInd): "
"alloc_skb failed\n");
free_page((u32)tempdata);
free_page((unsigned long)tempdata);
return;
}
memcpy(skb_put(result, templen), tempdata, templen);
free_page((u32)tempdata);
free_page((unsigned long)tempdata);
}
else {
/* modem mode */
......
......@@ -118,7 +118,7 @@ static int __devinit tpam_probe(struct pci_dev *dev, const struct pci_device_id
}
/* remap board memory */
if (!(card->bar0 = (unsigned long) ioremap(pci_resource_start(dev, 0),
if (!(card->bar0 = ioremap(pci_resource_start(dev, 0),
0x800000))) {
printk(KERN_ERR "TurboPAM: tpam_register_card: "
"unable to remap bar0\n");
......@@ -130,12 +130,12 @@ static int __devinit tpam_probe(struct pci_dev *dev, const struct pci_device_id
readl(card->bar0 + TPAM_RESETPAM_REGISTER);
/* initialisation magic :-( */
copy_to_pam_dword(card, (void *)0x01800008, 0x00000030);
copy_to_pam_dword(card, (void *)0x01800010, 0x00000030);
copy_to_pam_dword(card, (void *)0x01800014, 0x42240822);
copy_to_pam_dword(card, (void *)0x01800018, 0x07114000);
copy_to_pam_dword(card, (void *)0x0180001c, 0x00000400);
copy_to_pam_dword(card, (void *)0x01840070, 0x00000010);
copy_to_pam_dword(card, 0x01800008, 0x00000030);
copy_to_pam_dword(card, 0x01800010, 0x00000030);
copy_to_pam_dword(card, 0x01800014, 0x42240822);
copy_to_pam_dword(card, 0x01800018, 0x07114000);
copy_to_pam_dword(card, 0x0180001c, 0x00000400);
copy_to_pam_dword(card, 0x01840070, 0x00000010);
/* fill the ISDN link layer structure */
card->interface.owner = THIS_MODULE;
......@@ -201,7 +201,7 @@ static int __devinit tpam_probe(struct pci_dev *dev, const struct pci_device_id
return 0;
err_out_iounmap:
iounmap((void *)card->bar0);
iounmap(card->bar0);
err_out_free_irq:
free_irq(card->irq, card);
......@@ -231,7 +231,7 @@ static void __devexit tpam_unregister_card(struct pci_dev *pcidev, tpam_card *ca
free_irq(card->irq, card);
/* release mapped memory */
iounmap((void *)card->bar0);
iounmap(card->bar0);
pci_disable_device(pcidev);
}
......
......@@ -23,14 +23,14 @@
* addr: the address (in the board memory)
* val: the value to put into the memory.
*/
void copy_to_pam_dword(tpam_card *card, const void *addr, u32 val) {
void copy_to_pam_dword(tpam_card *card, u32 addr, u32 val) {
/* set the page register */
writel(((unsigned long)addr) | TPAM_PAGE_SIZE,
writel(addr | TPAM_PAGE_SIZE,
card->bar0 + TPAM_PAGE_REGISTER);
/* write the value */
writel(val, card->bar0 + (((unsigned long)addr) & TPAM_PAGE_SIZE));
writel(val, card->bar0 + (addr & TPAM_PAGE_SIZE));
}
/*
......@@ -42,15 +42,15 @@ void copy_to_pam_dword(tpam_card *card, const void *addr, u32 val) {
* from: the source address (in the kernel memory)
* n: number of bytes
*/
void copy_to_pam(tpam_card *card, void *to, const void *from, u32 n) {
void copy_to_pam(tpam_card *card, u32 to, const void *from, u32 n) {
u32 page, offset, count;
/* need to write in dword ! */
while (n & 3) n++;
while (n) {
page = ((u32)to) | TPAM_PAGE_SIZE;
offset = ((u32)to) & TPAM_PAGE_SIZE;
page = to | TPAM_PAGE_SIZE;
offset = to & TPAM_PAGE_SIZE;
count = n < TPAM_PAGE_SIZE - offset
? n
: TPAM_PAGE_SIZE - offset;
......@@ -59,7 +59,7 @@ void copy_to_pam(tpam_card *card, void *to, const void *from, u32 n) {
writel(page, card->bar0 + TPAM_PAGE_REGISTER);
/* copy the data */
memcpy_toio((void *)(card->bar0 + offset), from, count);
memcpy_toio(card->bar0 + offset, from, count);
from += count;
to += count;
......@@ -75,14 +75,14 @@ void copy_to_pam(tpam_card *card, void *to, const void *from, u32 n) {
*
* Return: the value read into the memory.
*/
u32 copy_from_pam_dword(tpam_card *card, const void *addr) {
u32 copy_from_pam_dword(tpam_card *card, u32 addr) {
/* set the page register */
writel(((u32)addr) | TPAM_PAGE_SIZE,
card->bar0 + TPAM_PAGE_REGISTER);
/* read the data */
return readl(card->bar0 + (((u32)addr) & TPAM_PAGE_SIZE));
return readl(card->bar0 + (addr & TPAM_PAGE_SIZE));
}
/*
......@@ -93,12 +93,12 @@ u32 copy_from_pam_dword(tpam_card *card, const void *addr) {
* from: the source address (in the board memory)
* n: number of bytes
*/
void copy_from_pam(tpam_card *card, void *to, const void *from, u32 n) {
void copy_from_pam(tpam_card *card, void *to, u32 from, u32 n) {
u32 page, offset, count;
while (n) {
page = ((u32)from) | TPAM_PAGE_SIZE;
offset = ((u32)from) & TPAM_PAGE_SIZE;
page = from | TPAM_PAGE_SIZE;
offset = from & TPAM_PAGE_SIZE;
count = n < TPAM_PAGE_SIZE - offset
? n
: TPAM_PAGE_SIZE - offset;
......@@ -107,7 +107,7 @@ void copy_from_pam(tpam_card *card, void *to, const void *from, u32 n) {
writel(page, card->bar0 + TPAM_PAGE_REGISTER);
/* read the data */
memcpy_fromio(to, (void *)(card->bar0 + offset), count);
memcpy_fromio(to, card->bar0 + offset, count);
from += count;
to += count;
......@@ -125,7 +125,7 @@ void copy_from_pam(tpam_card *card, void *to, const void *from, u32 n) {
*
* Return: 0 if OK, <0 if error.
*/
int copy_from_pam_to_user(tpam_card *card, void __user *to, const void *from, u32 n) {
int copy_from_pam_to_user(tpam_card *card, void __user *to, u32 from, u32 n) {
void *page;
u32 count;
......@@ -148,7 +148,7 @@ int copy_from_pam_to_user(tpam_card *card, void __user *to, const void *from, u3
if (copy_to_user(to, page, count)) {
/* this can fail... */
free_page((u32)page);
free_page((unsigned long)page);
return -EFAULT;
}
from += count;
......@@ -157,7 +157,7 @@ int copy_from_pam_to_user(tpam_card *card, void __user *to, const void *from, u3
}
/* release allocated memory */
free_page((u32)page);
free_page((unsigned long)page);
return 0;
}
......@@ -171,7 +171,7 @@ int copy_from_pam_to_user(tpam_card *card, void __user *to, const void *from, u3
*
* Return: 0 if OK, <0 if error.
*/
int copy_from_user_to_pam(tpam_card *card, void *to, const void __user *from, u32 n) {
int copy_from_user_to_pam(tpam_card *card, u32 to, const void __user *from, u32 n) {
void *page;
u32 count;
......@@ -188,7 +188,7 @@ int copy_from_user_to_pam(tpam_card *card, void *to, const void __user *from, u3
/* copy data from the user memory into the kernel memory */
if (copy_from_user(page, from, count)) {
/* this can fail... */
free_page((u32)page);
free_page((unsigned long)page);
return -EFAULT;
}
......@@ -203,7 +203,7 @@ int copy_from_user_to_pam(tpam_card *card, void *to, const void __user *from, u3
}
/* release allocated memory */
free_page((u32)page);
free_page((unsigned long)page);
return 0;
}
......
......@@ -90,10 +90,10 @@ irqreturn_t tpam_irq(int irq, void *dev_id, struct pt_regs *regs)
spin_lock(&card->lock);
/* get the message type */
ackupload = copy_from_pam_dword(card, (void *)TPAM_ACKUPLOAD_REGISTER);
ackupload = copy_from_pam_dword(card, TPAM_ACKUPLOAD_REGISTER);
/* acknowledge the interrupt */
copy_to_pam_dword(card, (void *)TPAM_INTERRUPTACK_REGISTER, 0);
copy_to_pam_dword(card, TPAM_INTERRUPTACK_REGISTER, 0);
readl(card->bar0 + TPAM_HINTACK_REGISTER);
if (!ackupload) {
......@@ -104,10 +104,10 @@ irqreturn_t tpam_irq(int irq, void *dev_id, struct pt_regs *regs)
/* get the upload pointer */
uploadptr = copy_from_pam_dword(card,
(void *)TPAM_UPLOADPTR_REGISTER);
TPAM_UPLOADPTR_REGISTER);
/* get the beginning of the message (pci_mpb part) */
copy_from_pam(card, &mpb, (void *)uploadptr, sizeof(pci_mpb));
copy_from_pam(card, &mpb, uploadptr, sizeof(pci_mpb));
/* allocate the sk_buff */
if (!(skb = alloc_skb(sizeof(skb_header) + sizeof(pci_mpb) +
......@@ -131,13 +131,13 @@ irqreturn_t tpam_irq(int irq, void *dev_id, struct pt_regs *regs)
/* copy the TLV block into the sk_buff */
copy_from_pam(card, skb_put(skb, mpb.actualBlockTLVSize),
(void *)uploadptr + sizeof(pci_mpb),
uploadptr + sizeof(pci_mpb),
mpb.actualBlockTLVSize);
/* if existent, copy the data block into the sk_buff */
if (mpb.actualDataSize)
copy_from_pam(card, skb_put(skb, mpb.actualDataSize),
(void *)uploadptr + sizeof(pci_mpb) + 4096,
uploadptr + sizeof(pci_mpb) + 4096,
mpb.actualDataSize);
/* wait for the board to become ready */
......@@ -154,7 +154,7 @@ irqreturn_t tpam_irq(int irq, void *dev_id, struct pt_regs *regs)
} while (hpic & 0x00000002);
/* acknowledge the message */
copy_to_pam_dword(card, (void *)TPAM_ACKDOWNLOAD_REGISTER,
copy_to_pam_dword(card, TPAM_ACKDOWNLOAD_REGISTER,
0xffffffff);
readl(card->bar0 + TPAM_DSPINT_REGISTER);
......@@ -362,15 +362,14 @@ static int tpam_sendpacket(tpam_card *card, tpam_channel *channel) {
card->id, skbh->size, skbh->data_size);
/* get the board's download pointer */
downloadptr = copy_from_pam_dword(card,
(void *)TPAM_DOWNLOADPTR_REGISTER);
downloadptr = copy_from_pam_dword(card, TPAM_DOWNLOADPTR_REGISTER);
/* copy the packet to the board at the downloadptr location */
copy_to_pam(card, (void *)downloadptr, skb->data + sizeof(skb_header),
copy_to_pam(card, downloadptr, skb->data + sizeof(skb_header),
skbh->size);
if (skbh->data_size)
/* if there is some data in the packet, copy it too */
copy_to_pam(card, (void *)downloadptr + sizeof(pci_mpb) + 4096,
copy_to_pam(card, downloadptr + sizeof(pci_mpb) + 4096,
skb->data + sizeof(skb_header) + skbh->size,
skbh->data_size);
......@@ -378,7 +377,7 @@ static int tpam_sendpacket(tpam_card *card, tpam_channel *channel) {
card->busy = 1;
/* interrupt the board */
copy_to_pam_dword(card, (void *)TPAM_ACKDOWNLOAD_REGISTER, 0);
copy_to_pam_dword(card, TPAM_ACKDOWNLOAD_REGISTER, 0);
readl(card->bar0 + TPAM_DSPINT_REGISTER);
/* release the lock */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment