]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/staging/keucr/ms.c
Staging: keucr driver: fix uninitialized variable & proper memset length
[net-next-2.6.git] / drivers / staging / keucr / ms.c
CommitLineData
126bb03b
AC
1#include <linux/slab.h>
2#include "usb.h"
3#include "scsiglue.h"
4#include "transport.h"
5#include "ms.h"
6
7//----- MS_ReaderCopyBlock() ------------------------------------------
8int MS_ReaderCopyBlock(struct us_data *us, WORD oldphy, WORD newphy, WORD PhyBlockAddr, BYTE PageNum, PBYTE buf, WORD len)
9{
10 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
11 int result;
12
13 //printk("MS_ReaderCopyBlock --- PhyBlockAddr = %x, PageNum = %x\n", PhyBlockAddr, PageNum);
14 result = ENE_LoadBinCode(us, MS_RW_PATTERN);
15 if (result != USB_STOR_XFER_GOOD)
16 return USB_STOR_TRANSPORT_ERROR;
17
307ae1d3 18 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
126bb03b
AC
19 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
20 bcb->DataTransferLength = 0x200*len;
21 bcb->Flags = 0x00;
22 bcb->CDB[0] = 0xF0;
23 bcb->CDB[1] = 0x08;
24 bcb->CDB[4] = (BYTE)(oldphy);
25 bcb->CDB[3] = (BYTE)(oldphy>>8);
26 bcb->CDB[2] = (BYTE)(oldphy>>16);
27 bcb->CDB[7] = (BYTE)(newphy);
28 bcb->CDB[6] = (BYTE)(newphy>>8);
29 bcb->CDB[5] = (BYTE)(newphy>>16);
30 bcb->CDB[9] = (BYTE)(PhyBlockAddr);
31 bcb->CDB[8] = (BYTE)(PhyBlockAddr>>8);
32 bcb->CDB[10] = PageNum;
33
34 result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0);
35 if (result != USB_STOR_XFER_GOOD)
36 return USB_STOR_TRANSPORT_ERROR;
37
38 return USB_STOR_TRANSPORT_GOOD;
39}
40
41//----- MS_ReaderReadPage() ------------------------------------------
42int MS_ReaderReadPage(struct us_data *us, DWORD PhyBlockAddr, BYTE PageNum, PDWORD PageBuf, MS_LibTypeExtdat *ExtraDat)
43{
44 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
45 int result;
46 BYTE ExtBuf[4];
47 DWORD bn = PhyBlockAddr * 0x20 + PageNum;
48
49 //printk("MS --- MS_ReaderReadPage, PhyBlockAddr = %x, PageNum = %x\n", PhyBlockAddr, PageNum);
50
51 result = ENE_LoadBinCode(us, MS_RW_PATTERN);
52 if (result != USB_STOR_XFER_GOOD)
53 return USB_STOR_TRANSPORT_ERROR;
54
55 // Read Page Data
307ae1d3 56 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
126bb03b
AC
57 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
58 bcb->DataTransferLength = 0x200;
59 bcb->Flags = 0x80;
60 bcb->CDB[0] = 0xF1;
61 bcb->CDB[1] = 0x02;
62 bcb->CDB[5] = (BYTE)(bn);
63 bcb->CDB[4] = (BYTE)(bn>>8);
64 bcb->CDB[3] = (BYTE)(bn>>16);
65 bcb->CDB[2] = (BYTE)(bn>>24);
66
67 result = ENE_SendScsiCmd(us, FDIR_READ, PageBuf, 0);
68 if (result != USB_STOR_XFER_GOOD)
69 return USB_STOR_TRANSPORT_ERROR;
70
71 // Read Extra Data
307ae1d3 72 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
126bb03b
AC
73 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
74 bcb->DataTransferLength = 0x4;
75 bcb->Flags = 0x80;
76 bcb->CDB[0] = 0xF1;
77 bcb->CDB[1] = 0x03;
78 bcb->CDB[5] = (BYTE)(PageNum);
79 bcb->CDB[4] = (BYTE)(PhyBlockAddr);
80 bcb->CDB[3] = (BYTE)(PhyBlockAddr>>8);
81 bcb->CDB[2] = (BYTE)(PhyBlockAddr>>16);
82 bcb->CDB[6] = 0x01;
83
84 result = ENE_SendScsiCmd(us, FDIR_READ, &ExtBuf, 0);
85 if (result != USB_STOR_XFER_GOOD)
86 return USB_STOR_TRANSPORT_ERROR;
87
88 ExtraDat->reserved = 0;
89