9
9
*
10
10
* Author: Conor Dooley <[email protected] >
11
11
*/
12
+ #include <linux/cleanup.h>
12
13
#include <linux/debugfs.h>
13
14
#include <linux/firmware.h>
14
15
#include <linux/math.h>
@@ -233,15 +234,17 @@ static int mpfs_auto_update_verify_image(struct fw_upload *fw_uploader)
233
234
return ret ;
234
235
}
235
236
236
- static int mpfs_auto_update_set_image_address (struct mpfs_auto_update_priv * priv , char * buffer ,
237
+ static int mpfs_auto_update_set_image_address (struct mpfs_auto_update_priv * priv ,
237
238
u32 image_address , loff_t directory_address )
238
239
{
239
240
struct erase_info erase ;
240
- size_t erase_size = AUTO_UPDATE_DIRECTORY_SIZE ;
241
+ size_t erase_size = round_up ( AUTO_UPDATE_DIRECTORY_SIZE , ( u64 ) priv -> flash -> erasesize ) ;
241
242
size_t bytes_written = 0 , bytes_read = 0 ;
243
+ char * buffer __free (kfree ) = kzalloc (erase_size , GFP_KERNEL );
242
244
int ret ;
243
245
244
- erase_size = round_up (erase_size , (u64 )priv -> flash -> erasesize );
246
+ if (!buffer )
247
+ return - ENOMEM ;
245
248
246
249
erase .addr = AUTO_UPDATE_DIRECTORY_BASE ;
247
250
erase .len = erase_size ;
@@ -287,7 +290,7 @@ static int mpfs_auto_update_set_image_address(struct mpfs_auto_update_priv *priv
287
290
return ret ;
288
291
289
292
if (bytes_written != erase_size )
290
- return ret ;
293
+ return - EIO ;
291
294
292
295
return 0 ;
293
296
}
@@ -297,7 +300,6 @@ static int mpfs_auto_update_write_bitstream(struct fw_upload *fw_uploader, const
297
300
{
298
301
struct mpfs_auto_update_priv * priv = fw_uploader -> dd_handle ;
299
302
struct erase_info erase ;
300
- char * buffer ;
301
303
loff_t directory_address = AUTO_UPDATE_UPGRADE_DIRECTORY ;
302
304
size_t erase_size = AUTO_UPDATE_DIRECTORY_SIZE ;
303
305
size_t bytes_written = 0 ;
@@ -313,16 +315,12 @@ static int mpfs_auto_update_write_bitstream(struct fw_upload *fw_uploader, const
313
315
image_address = AUTO_UPDATE_BITSTREAM_BASE +
314
316
AUTO_UPDATE_UPGRADE_INDEX * priv -> size_per_bitstream ;
315
317
316
- buffer = devm_kzalloc (priv -> dev , erase_size , GFP_KERNEL );
317
- if (!buffer )
318
- return - ENOMEM ;
319
-
320
318
/*
321
319
* For bitstream info, the descriptor is written to a fixed offset,
322
320
* so there is no need to set the image address.
323
321
*/
324
322
if (!is_info ) {
325
- ret = mpfs_auto_update_set_image_address (priv , buffer , image_address , directory_address );
323
+ ret = mpfs_auto_update_set_image_address (priv , image_address , directory_address );
326
324
if (ret ) {
327
325
dev_err (priv -> dev , "failed to set image address in the SPI directory: %d\n" , ret );
328
326
return ret ;
@@ -345,7 +343,7 @@ static int mpfs_auto_update_write_bitstream(struct fw_upload *fw_uploader, const
345
343
dev_info (priv -> dev , "Erasing the flash at address (0x%x)\n" , image_address );
346
344
ret = mtd_erase (priv -> flash , & erase );
347
345
if (ret )
348
- goto out ;
346
+ return ret ;
349
347
350
348
/*
351
349
* No parsing etc of the bitstream is required. The system controller
@@ -355,19 +353,15 @@ static int mpfs_auto_update_write_bitstream(struct fw_upload *fw_uploader, const
355
353
dev_info (priv -> dev , "Writing the image to the flash at address (0x%x)\n" , image_address );
356
354
ret = mtd_write (priv -> flash , (loff_t )image_address , size , & bytes_written , data );
357
355
if (ret )
358
- goto out ;
356
+ return ret ;
359
357
360
- if (bytes_written != size ) {
361
- ret = - EIO ;
362
- goto out ;
363
- }
358
+ if (bytes_written != size )
359
+ return - EIO ;
364
360
365
361
* written = bytes_written ;
366
362
dev_info (priv -> dev , "Wrote 0x%zx bytes to the flash\n" , bytes_written );
367
363
368
- out :
369
- devm_kfree (priv -> dev , buffer );
370
- return ret ;
364
+ return 0 ;
371
365
}
372
366
373
367
static enum fw_upload_err mpfs_auto_update_write (struct fw_upload * fw_uploader , const u8 * data ,
0 commit comments