Skip to content

Commit 0bdf9b3

Browse files
Magnus DammDominik Brodowski
authored andcommitted
pcmcia: Change window_handle_t logic to unsigned long
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>
1 parent 16456eb commit 0bdf9b3

6 files changed

Lines changed: 36 additions & 41 deletions

File tree

‎drivers/net/pcmcia/pcnet_cs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
15141514
if (i != (TX_PAGES<<8)) {
15151515
iounmap(info->base);
15161516
pcmcia_release_window(link, link->win);
1517-
info->base = NULL; link->win = NULL;
1517+
info->base = NULL; link->win = 0;
15181518
goto failed;
15191519
}
15201520

‎drivers/pcmcia/cs_internal.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ extern struct list_head pcmcia_socket_list;
149149
extern struct class pcmcia_socket_class;
150150

151151
int pcmcia_get_window(struct pcmcia_socket *s,
152-
window_handle_t *handle,
153-
int idx,
152+
window_handle_t *wh_out,
153+
window_handle_t wh,
154154
win_req_t *req);
155155
int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
156156
struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr);

‎drivers/pcmcia/pcmcia_ioctl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,12 @@ static int ds_ioctl(struct inode * inode, struct file * file,
916916
goto free_out;
917917
break;
918918
case DS_GET_FIRST_WINDOW:
919-
ret = pcmcia_get_window(s, &buf->win_info.handle, 0,
919+
ret = pcmcia_get_window(s, &buf->win_info.handle, 1,
920920
&buf->win_info.window);
921921
break;
922922
case DS_GET_NEXT_WINDOW:
923923
ret = pcmcia_get_window(s, &buf->win_info.handle,
924-
buf->win_info.handle->index + 1, &buf->win_info.window);
924+
buf->win_info.handle + 1, &buf->win_info.window);
925925
break;
926926
case DS_GET_MEM_PAGE:
927927
ret = pcmcia_get_mem_page(s, buf->win_info.handle,

‎drivers/pcmcia/pcmcia_resource.c‎

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,19 @@ EXPORT_SYMBOL(pcmcia_access_configuration_register);
187187

188188
/** pcmcia_get_window
189189
*/
190-
int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
191-
int idx, win_req_t *req)
190+
int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *wh_out,
191+
window_handle_t wh, win_req_t *req)
192192
{
193193
window_t *win;
194-
int w;
194+
window_handle_t w;
195195

196196
if (!s || !(s->state & SOCKET_PRESENT))
197197
return -ENODEV;
198-
for (w = idx; w < MAX_WIN; w++)
198+
199+
wh--;
200+
if (wh >= MAX_WIN)
201+
return -EINVAL;
202+
for (w = wh; w < MAX_WIN; w++)
199203
if (s->state & SOCKET_WIN_REQ(w))
200204
break;
201205
if (w == MAX_WIN)
@@ -213,7 +217,8 @@ int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
213217
req->Attributes |= WIN_DATA_WIDTH_16;
214218
if (win->ctl.flags & MAP_USE_WAIT)
215219
req->Attributes |= WIN_USE_WAIT;
216-
*handle = win;
220+
221+
*wh_out = w++;
217222
return 0;
218223
} /* pcmcia_get_window */
219224
EXPORT_SYMBOL(pcmcia_get_window);
@@ -226,12 +231,12 @@ EXPORT_SYMBOL(pcmcia_get_window);
226231
int pcmcia_get_mem_page(struct pcmcia_socket *skt, window_handle_t wh,
227232
memreq_t *req)
228233
{
229-
window_handle_t win = wh;
230-
231-
if ((win == NULL) || (win->magic != WINDOW_MAGIC))
234+
wh--;
235+
if (wh >= MAX_WIN)
232236
return -EINVAL;
237+
233238
req->Page = 0;
234-
req->CardOffset = win->ctl.card_start;
239+
req->CardOffset = skt->win[wh].ctl.card_start;
235240
return 0;
236241
} /* pcmcia_get_mem_page */
237242
EXPORT_SYMBOL(pcmcia_get_mem_page);
@@ -240,18 +245,17 @@ EXPORT_SYMBOL(pcmcia_get_mem_page);
240245
int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh,
241246
memreq_t *req)
242247
{
243-
struct pcmcia_socket *s;
244-
window_handle_t win = wh;
248+
struct pcmcia_socket *s = p_dev->socket;
245249

246-
if ((win == NULL) || (win->magic != WINDOW_MAGIC))
250+
wh--;
251+
if (wh >= MAX_WIN)
247252
return -EINVAL;
248-
s = win->sock;
249253
if (req->Page != 0) {
250254
dev_dbg(&s->dev, "failure: requested page is zero\n");
251255
return -EINVAL;
252256
}
253-
win->ctl.card_start = req->CardOffset;
254-
if (s->ops->set_mem_map(s, &win->ctl) != 0) {
257+
s->win[wh].ctl.card_start = req->CardOffset;
258+
if (s->ops->set_mem_map(s, &s->win[wh].ctl) != 0) {
255259
dev_dbg(&s->dev, "failed to set_mem_map\n");
256260
return -EIO;
257261
}
@@ -450,31 +454,32 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
450454

451455
int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t wh)
452456
{
453-
struct pcmcia_socket *s;
454-
window_handle_t win = wh;
457+
struct pcmcia_socket *s = p_dev->socket;
458+
window_t *win;
455459

456-
if ((win == NULL) || (win->magic != WINDOW_MAGIC))
460+
wh--;
461+
if (wh >= MAX_WIN)
457462
return -EINVAL;
458-
s = win->sock;
459-
if (!(win->handle->_win & CLIENT_WIN_REQ(win->index))) {
463+
464+
win = &s->win[wh];
465+
466+
if (!(p_dev->_win & CLIENT_WIN_REQ(wh))) {
460467
dev_dbg(&s->dev, "not releasing unknown window\n");
461468
return -EINVAL;
462469
}
463470

464471
/* Shut down memory window */
465472
win->ctl.flags &= ~MAP_ACTIVE;
466473
s->ops->set_mem_map(s, &win->ctl);
467-
s->state &= ~SOCKET_WIN_REQ(win->index);
474+
s->state &= ~SOCKET_WIN_REQ(wh);
468475

469476
/* Release system memory */
470477
if (win->ctl.res) {
471478
release_resource(win->ctl.res);
472479
kfree(win->ctl.res);
473480
win->ctl.res = NULL;
474481
}
475-
win->handle->_win &= ~CLIENT_WIN_REQ(win->index);
476-
477-
win->magic = 0;
482+
p_dev->_win &= ~CLIENT_WIN_REQ(wh);
478483

479484
return 0;
480485
} /* pcmcia_release_window */
@@ -847,10 +852,6 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
847852
}
848853

849854
win = &s->win[w];
850-
win->magic = WINDOW_MAGIC;
851-
win->index = w;
852-
win->handle = *p_dev;
853-
win->sock = s;
854855

855856
if (!(s->features & SS_CAP_STATIC_MAP)) {
856857
win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
@@ -887,7 +888,7 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
887888
} else {
888889
req->Base = win->ctl.res->start;
889890
}
890-
*wh = win;
891+
*wh = w + 1;
891892

892893
return 0;
893894
} /* pcmcia_request_window */

‎include/pcmcia/cs_types.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ typedef u_int event_t;
2626
typedef u_char cisdata_t;
2727
typedef u_short page_t;
2828

29-
struct window_t;
30-
typedef struct window_t *window_handle_t;
29+
typedef unsigned long window_handle_t;
3130

3231
struct region_t;
3332
typedef struct region_t *memory_handle_t;

‎include/pcmcia/ss.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,7 @@ typedef struct io_window_t {
107107
struct resource *res;
108108
} io_window_t;
109109

110-
#define WINDOW_MAGIC 0xB35C
111110
typedef struct window_t {
112-
u_short magic;
113-
u_short index;
114-
struct pcmcia_device *handle;
115-
struct pcmcia_socket *sock;
116111
pccard_mem_map ctl;
117112
} window_t;
118113

0 commit comments

Comments
 (0)