ajuckler commented on code in PR #17376:
URL: https://github.com/apache/nuttx/pull/17376#discussion_r2562302189
##########
drivers/eeprom/i2c_xx24xx.c:
##########
@@ -327,6 +327,149 @@ static int ee24xx_writepage(FAR struct ee24xx_dev_s
*eedev, uint32_t memaddr,
return I2C_TRANSFER(eedev->i2c, msgs, 2);
}
+/****************************************************************************
+ * Name: ee24xx_eraseall
+ *
+ * Description:
+ * Erase all data on the device
+ *
+ * Input Parameters:
+ * eedev - Device structure
+ *
+ ****************************************************************************/
+
+static int ee24xx_eraseall(FAR struct ee24xx_dev_s *eedev)
+{
+ FAR uint8_t *buf;
+ off_t offset;
+ int ret;
+
+ DEBUGASSERT(eedev);
+
+ if (eedev->readonly)
+ {
+ return -EACCES;
+ }
+
+ buf = kmm_malloc(eedev->pgsize);
+ if (buf == NULL)
+ {
+ ferr("ERROR: Failed to allocate memory for ee24xx eraseall\n");
+ return -ENOMEM;
+ }
+
+ memset(buf, 0xff, eedev->pgsize);
+
+ ret = nxmutex_lock(&eedev->lock);
+ if (ret < 0)
+ {
+ goto free_buffer;
+ }
+
+ for (offset = 0; offset < eedev->size; offset += eedev->pgsize)
+ {
+ ret = ee24xx_writepage(eedev, offset, (char *)buf, eedev->pgsize);
+ if (ret < 0)
+ {
+ ferr("ERROR: Failed to write page at offset %" PRIdOFF \
+ " (ret = %d)",
+ offset, ret);
+ goto release_semaphore;
+ }
+
+ ret = ee24xx_waitwritecomplete(eedev, offset);
+ if (ret < 0)
+ {
+ ferr("ERROR while waiting for write at offset %" PRIdOFF \
+ " to complete (ret = %d)",
+ offset, ret);
+ goto release_semaphore;
+ }
+ }
+
+release_semaphore:
+ nxmutex_unlock(&eedev->lock);
+
+free_buffer:
+ kmm_free(buf);
+
Review Comment:
Done, but do we have any specific guideline requiring this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]