1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -492,7 +492,7 @@ static int spinand_program_page(struct s
#ifdef CONFIG_MTD_SPINAND_ONDIEECC
unsigned int i, j;
- wbuf = devm_kzalloc(&spi_nand->dev, CACHE_BUF, GFP_KERNEL);
+ wbuf = kzalloc(CACHE_BUF, GFP_KERNEL);
if (!wbuf)
return -ENOMEM;
@@ -500,7 +500,7 @@ static int spinand_program_page(struct s
retval = spinand_read_page(spi_nand, page_id, 0, CACHE_BUF, wbuf);
if (retval < 0) {
dev_err(&spi_nand->dev, "ecc error on read page!!!\n");
- return retval;
+ goto cleanup;
}
for (i = offset, j = 0; i < len; i++, j++)
@@ -510,7 +510,7 @@ static int spinand_program_page(struct s
retval = spinand_enable_ecc(spi_nand);
if (retval < 0) {
dev_err(&spi_nand->dev, "enable ecc failed!!\n");
- return retval;
+ goto cleanup;
}
}
#else
@@ -519,7 +519,7 @@ static int spinand_program_page(struct s
retval = spinand_write_enable(spi_nand);
if (retval < 0) {
dev_err(&spi_nand->dev, "write enable failed!!\n");
- return retval;
+ goto cleanup;
}
if (wait_till_ready(spi_nand))
dev_err(&spi_nand->dev, "wait timedout!!!\n");
@@ -527,23 +527,24 @@ static int spinand_program_page(struct s
retval = spinand_program_data_to_cache(spi_nand, page_id,
offset, len, wbuf);
if (retval < 0)
- return retval;
+ goto cleanup;
retval = spinand_program_execute(spi_nand, page_id);
if (retval < 0)
- return retval;
+ goto cleanup;
while (1) {
retval = spinand_read_status(spi_nand, &status);
if (retval < 0) {
dev_err(&spi_nand->dev,
"error %d reading status register\n", retval);
- return retval;
+ goto cleanup;
}
if ((status & STATUS_OIP_MASK) == STATUS_READY) {
if ((status & STATUS_P_FAIL_MASK) == STATUS_P_FAIL) {
dev_err(&spi_nand->dev,
"program error, page %d\n", page_id);
- return -1;
+ retval = -1;
+ goto cleanup;
}
break;
}
@@ -553,13 +554,20 @@ static int spinand_program_page(struct s
retval = spinand_disable_ecc(spi_nand);
if (retval < 0) {
dev_err(&spi_nand->dev, "disable ecc failed!!\n");
- return retval;
+ goto cleanup;
}
enable_hw_ecc = 0;
}
+ kfree(wbuf);
#endif
-
return 0;
+
+cleanup:
+#ifdef CONFIG_MTD_SPINAND_ONDIEECC
+ kfree(wbuf);
+#endif
+ return retval;
+
}
/**
|