aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Roskin <proski@gnu.org>2007-06-16 03:39:07 -0400
committerGuido Guenther <agx@sigxcpu.org>2007-06-16 13:42:59 +0200
commit9c747625775d0a13a756720f98f11d49b329b71f (patch)
treed7d05e5c19ca00f3ffe954abd06a6fbbdb786c4e
parent14452d5c8535fb4428028958343f58c1132099a5 (diff)
[PATCH] Eliminate struct dfu_ctx
There is no point in having that structure. Whatever was inside is allocated and used individually now. Signed-off-by: Pavel Roskin <proski@gnu.org>
-rw-r--r--at76_usb.c71
1 files changed, 20 insertions, 51 deletions
diff --git a/at76_usb.c b/at76_usb.c
index 3e555e2..0555356 100644
--- a/at76_usb.c
+++ b/at76_usb.c
@@ -221,40 +221,25 @@ struct dfu_status {
unsigned char string;
} __attribute__ ((packed));
-/* driver independent download context */
-struct dfu_ctx {
- struct usb_device *udev;
- u8 dfu_state;
- struct dfu_status dfu_status;
- void *buf;
-};
-
-static int at76_dfu_download_block(struct dfu_ctx *ctx, u8 *buffer, int bytes,
- int block)
+static int at76_dfu_download_block(struct usb_device *udev, u8 *buffer,
+ int bytes, int block)
{
int result;
- u8 *tmpbuf = ctx->buf;
- struct usb_device *udev = ctx->udev;
at76_dbg(DBG_DFU, "dfu_download_block(): buffer=%p, bytes=%d, block=%d",
buffer, bytes, block);
- if (tmpbuf == NULL)
- return -ENOMEM;
-
- memcpy(tmpbuf, buffer, bytes);
-
result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), DFU_DNLOAD,
USB_TYPE_CLASS | USB_DIR_OUT |
- USB_RECIP_INTERFACE, block, 0, tmpbuf, bytes,
+ USB_RECIP_INTERFACE, block, 0, buffer, bytes,
USB_CTRL_GET_TIMEOUT);
return result;
}
-static int at76_dfu_get_status(struct dfu_ctx *ctx, struct dfu_status *status)
+static int at76_dfu_get_status(struct usb_device *udev,
+ struct dfu_status *status)
{
int result;
- struct usb_device *udev = ctx->udev;
result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), DFU_GETSTATUS,
USB_TYPE_CLASS | USB_DIR_IN |
@@ -283,26 +268,13 @@ static inline u32 at76_get_timeout(struct dfu_status *s)
return ret;
}
-static struct dfu_ctx *at76_dfu_alloc_ctx(struct usb_device *udev)
-{
- struct dfu_ctx *ctx;
-
- ctx = kmalloc(sizeof(struct dfu_ctx) + DFU_PACKETSIZE,
- GFP_KERNEL | GFP_DMA);
- if (ctx) {
- ctx->udev = udev;
- ctx->buf = &(ctx[1]);
- }
- return ctx;
-}
-
/* if manifest_sync_timeout > 0 use this timeout (in msec) instead of the
one reported by the device in state MANIFEST_SYNC */
static int at76_usbdfu_download(struct usb_device *udev, u8 *dfu_buffer,
u32 dfu_len, int manifest_sync_timeout)
{
- struct dfu_ctx *ctx;
- struct dfu_status *dfu_stat_buf;
+ u8 *dmabuf;
+ struct dfu_status dfu_stat_buf;
int status = 0;
int need_dfu_state = 1;
int is_done = 0;
@@ -321,30 +293,27 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *dfu_buffer,
return -EINVAL;
}
- ctx = at76_dfu_alloc_ctx(udev);
- if (ctx == NULL)
+ dmabuf = kmalloc(DFU_PACKETSIZE, GFP_KERNEL | GFP_DMA);
+ if (dmabuf == NULL)
return -ENOMEM;
- dfu_stat_buf = &ctx->dfu_status;
-
do {
if (need_dfu_state) {
- status = at76_dfu_get_state(ctx->udev, &ctx->dfu_state);
+ status = at76_dfu_get_state(udev, &dfu_state);
if (!DFU_USB_SUCCESS(status)) {
err("DFU: Failed to get DFU state: %d", status);
goto exit;
}
- dfu_state = ctx->dfu_state;
need_dfu_state = 0;
}
switch (dfu_state) {
case STATE_DFU_DOWNLOAD_SYNC:
at76_dbg(DBG_DFU, "STATE_DFU_DOWNLOAD_SYNC");
- status = at76_dfu_get_status(ctx, dfu_stat_buf);
+ status = at76_dfu_get_status(udev, &dfu_stat_buf);
if (DFU_USB_SUCCESS(status)) {
- dfu_state = dfu_stat_buf->state;
- dfu_timeout = at76_get_timeout(dfu_stat_buf);
+ dfu_state = dfu_stat_buf.state;
+ dfu_timeout = at76_get_timeout(&dfu_stat_buf);
need_dfu_state = 0;
} else
err("at76_dfu_get_status failed with %d",
@@ -372,9 +341,9 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *dfu_buffer,
dfu_block_bytes = DFU_PACKETSIZE;
dfu_bytes_left -= dfu_block_bytes;
- status = at76_dfu_download_block(ctx,
- dfu_buffer +
- dfu_buffer_offset,
+ memcpy(dmabuf, dfu_buffer + dfu_buffer_offset,
+ dfu_block_bytes);
+ status = at76_dfu_download_block(udev, dmabuf,
dfu_block_bytes,
dfu_block_cnt);
dfu_buffer_offset += dfu_block_bytes;
@@ -389,11 +358,11 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *dfu_buffer,
case STATE_DFU_MANIFEST_SYNC:
at76_dbg(DBG_DFU, "STATE_DFU_MANIFEST_SYNC");
- status = at76_dfu_get_status(ctx, dfu_stat_buf);
+ status = at76_dfu_get_status(udev, &dfu_stat_buf);
if (DFU_USB_SUCCESS(status)) {
- dfu_state = dfu_stat_buf->state;
- dfu_timeout = at76_get_timeout(dfu_stat_buf);
+ dfu_state = dfu_stat_buf.state;
+ dfu_timeout = at76_get_timeout(&dfu_stat_buf);
need_dfu_state = 0;
/* override the timeout from the status response,
@@ -435,7 +404,7 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *dfu_buffer,
} while (!is_done && DFU_USB_SUCCESS(status));
exit:
- kfree(ctx);
+ kfree(dmabuf);
if (status < 0)
return status;
else