Skip to content

Commit

Permalink
pcmcia: Change window_handle_t logic to unsigned long
Browse files Browse the repository at this point in the history
Logic changes based on top of the other patches:

This set of patches changed window_handle_t from being a pointer to an
unsigned long. The unsigned long is now a simple index into socket->win[].
Going from a pointer to unsigned long should leave the user space interface
unchanged unless I'm mistaken.

This change results in code that is less error prone and a user space
interface which is much cleaner and safer. A nice side effect is that we
are also are able to remove all members except one from window_t.

[ linux@dominikbrodowski.net:
	Update to 2.6.31. Also, a plain "index" to socket->win[] does not
	work, as several codepaths rely on "window_handle_t" being
	non-zero if used. Therefore, set the window_handle_t to the
	socket->win[] index + 1. ]

CC: netdev@vger.kernel.org
Signed-off-by: Magnus Damm <damm@opensource.se>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
  • Loading branch information
Magnus Damm authored and Dominik Brodowski committed Nov 28, 2009
1 parent 16456eb commit 0bdf9b3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 41 deletions.
2 changes: 1 addition & 1 deletion drivers/net/pcmcia/pcnet_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
if (i != (TX_PAGES<<8)) {
iounmap(info->base);
pcmcia_release_window(link, link->win);
info->base = NULL; link->win = NULL;
info->base = NULL; link->win = 0;
goto failed;
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/pcmcia/cs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ extern struct list_head pcmcia_socket_list;
extern struct class pcmcia_socket_class;

int pcmcia_get_window(struct pcmcia_socket *s,
window_handle_t *handle,
int idx,
window_handle_t *wh_out,
window_handle_t wh,
win_req_t *req);
int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr);
Expand Down
4 changes: 2 additions & 2 deletions drivers/pcmcia/pcmcia_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,12 +916,12 @@ static int ds_ioctl(struct inode * inode, struct file * file,
goto free_out;
break;
case DS_GET_FIRST_WINDOW:
ret = pcmcia_get_window(s, &buf->win_info.handle, 0,
ret = pcmcia_get_window(s, &buf->win_info.handle, 1,
&buf->win_info.window);
break;
case DS_GET_NEXT_WINDOW:
ret = pcmcia_get_window(s, &buf->win_info.handle,
buf->win_info.handle->index + 1, &buf->win_info.window);
buf->win_info.handle + 1, &buf->win_info.window);
break;
case DS_GET_MEM_PAGE:
ret = pcmcia_get_mem_page(s, buf->win_info.handle,
Expand Down
59 changes: 30 additions & 29 deletions drivers/pcmcia/pcmcia_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,19 @@ EXPORT_SYMBOL(pcmcia_access_configuration_register);

/** pcmcia_get_window
*/
int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
int idx, win_req_t *req)
int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *wh_out,
window_handle_t wh, win_req_t *req)
{
window_t *win;
int w;
window_handle_t w;

if (!s || !(s->state & SOCKET_PRESENT))
return -ENODEV;
for (w = idx; w < MAX_WIN; w++)

wh--;
if (wh >= MAX_WIN)
return -EINVAL;
for (w = wh; w < MAX_WIN; w++)
if (s->state & SOCKET_WIN_REQ(w))
break;
if (w == MAX_WIN)
Expand All @@ -213,7 +217,8 @@ int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
req->Attributes |= WIN_DATA_WIDTH_16;
if (win->ctl.flags & MAP_USE_WAIT)
req->Attributes |= WIN_USE_WAIT;
*handle = win;

*wh_out = w++;
return 0;
} /* pcmcia_get_window */
EXPORT_SYMBOL(pcmcia_get_window);
Expand All @@ -226,12 +231,12 @@ EXPORT_SYMBOL(pcmcia_get_window);
int pcmcia_get_mem_page(struct pcmcia_socket *skt, window_handle_t wh,
memreq_t *req)
{
window_handle_t win = wh;

if ((win == NULL) || (win->magic != WINDOW_MAGIC))
wh--;
if (wh >= MAX_WIN)
return -EINVAL;

req->Page = 0;
req->CardOffset = win->ctl.card_start;
req->CardOffset = skt->win[wh].ctl.card_start;
return 0;
} /* pcmcia_get_mem_page */
EXPORT_SYMBOL(pcmcia_get_mem_page);
Expand All @@ -240,18 +245,17 @@ EXPORT_SYMBOL(pcmcia_get_mem_page);
int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh,
memreq_t *req)
{
struct pcmcia_socket *s;
window_handle_t win = wh;
struct pcmcia_socket *s = p_dev->socket;

if ((win == NULL) || (win->magic != WINDOW_MAGIC))
wh--;
if (wh >= MAX_WIN)
return -EINVAL;
s = win->sock;
if (req->Page != 0) {
dev_dbg(&s->dev, "failure: requested page is zero\n");
return -EINVAL;
}
win->ctl.card_start = req->CardOffset;
if (s->ops->set_mem_map(s, &win->ctl) != 0) {
s->win[wh].ctl.card_start = req->CardOffset;
if (s->ops->set_mem_map(s, &s->win[wh].ctl) != 0) {
dev_dbg(&s->dev, "failed to set_mem_map\n");
return -EIO;
}
Expand Down Expand Up @@ -450,31 +454,32 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)

int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t wh)
{
struct pcmcia_socket *s;
window_handle_t win = wh;
struct pcmcia_socket *s = p_dev->socket;
window_t *win;

if ((win == NULL) || (win->magic != WINDOW_MAGIC))
wh--;
if (wh >= MAX_WIN)
return -EINVAL;
s = win->sock;
if (!(win->handle->_win & CLIENT_WIN_REQ(win->index))) {

win = &s->win[wh];

if (!(p_dev->_win & CLIENT_WIN_REQ(wh))) {
dev_dbg(&s->dev, "not releasing unknown window\n");
return -EINVAL;
}

/* Shut down memory window */
win->ctl.flags &= ~MAP_ACTIVE;
s->ops->set_mem_map(s, &win->ctl);
s->state &= ~SOCKET_WIN_REQ(win->index);
s->state &= ~SOCKET_WIN_REQ(wh);

/* Release system memory */
if (win->ctl.res) {
release_resource(win->ctl.res);
kfree(win->ctl.res);
win->ctl.res = NULL;
}
win->handle->_win &= ~CLIENT_WIN_REQ(win->index);

win->magic = 0;
p_dev->_win &= ~CLIENT_WIN_REQ(wh);

return 0;
} /* pcmcia_release_window */
Expand Down Expand Up @@ -847,10 +852,6 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
}

win = &s->win[w];
win->magic = WINDOW_MAGIC;
win->index = w;
win->handle = *p_dev;
win->sock = s;

if (!(s->features & SS_CAP_STATIC_MAP)) {
win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
Expand Down Expand Up @@ -887,7 +888,7 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
} else {
req->Base = win->ctl.res->start;
}
*wh = win;
*wh = w + 1;

return 0;
} /* pcmcia_request_window */
Expand Down
3 changes: 1 addition & 2 deletions include/pcmcia/cs_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ typedef u_int event_t;
typedef u_char cisdata_t;
typedef u_short page_t;

struct window_t;
typedef struct window_t *window_handle_t;
typedef unsigned long window_handle_t;

struct region_t;
typedef struct region_t *memory_handle_t;
Expand Down
5 changes: 0 additions & 5 deletions include/pcmcia/ss.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ typedef struct io_window_t {
struct resource *res;
} io_window_t;

#define WINDOW_MAGIC 0xB35C
typedef struct window_t {
u_short magic;
u_short index;
struct pcmcia_device *handle;
struct pcmcia_socket *sock;
pccard_mem_map ctl;
} window_t;

Expand Down

0 comments on commit 0bdf9b3

Please sign in to comment.