struct nand_device_s *nand)
 {
        s3c24xx_nand_controller_t *info;
-
-       info = s3c24xx_nand_device_command(cmd_ctx, cmd, args, argc, nand);
-       if (info == NULL) {
-               return ERROR_NAND_DEVICE_INVALID;
-       }
+       CALL_S3C24XX_DEVICE_COMMAND(nand, &info);
 
        /* fill in the address fields for the core device */
        info->cmd = S3C2410_NFCMD;
 
                                struct nand_device_s *nand)
 {
        s3c24xx_nand_controller_t *info;
-
-       info = s3c24xx_nand_device_command(cmd_ctx, cmd, args, argc, nand);
-       if (info == NULL) {
-               return ERROR_NAND_DEVICE_INVALID;
-       }
+       CALL_S3C24XX_DEVICE_COMMAND(nand, &info);
 
        /* fill in the address fields for the core device */
        info->cmd = S3C2440_NFCMD;
 
                                struct nand_device_s *nand)
 {
        s3c24xx_nand_controller_t *info;
-
-       info = s3c24xx_nand_device_command(cmd_ctx, cmd, args, argc, nand);
-       if (info == NULL) {
-               return ERROR_NAND_DEVICE_INVALID;
-       }
+       CALL_S3C24XX_DEVICE_COMMAND(nand, &info);
 
        /* fill in the address fields for the core device */
        info->cmd = S3C2440_NFCMD;
 
                                struct nand_device_s *nand)
 {
        s3c24xx_nand_controller_t *info;
-
-       info = s3c24xx_nand_device_command(cmd_ctx, cmd, args, argc, nand);
-       if (info == NULL) {
-               return ERROR_NAND_DEVICE_INVALID;
-       }
+       CALL_S3C24XX_DEVICE_COMMAND(nand, &info);
 
        /* fill in the address fields for the core device */
        info->cmd = S3C2440_NFCMD;
 
 #include "s3c24xx_nand.h"
 
 
-s3c24xx_nand_controller_t *
-s3c24xx_nand_device_command(struct command_context_s *cmd_ctx, char *cmd,
-                           char **args, int argc,
-                           struct nand_device_s *nand)
+S3C24XX_DEVICE_COMMAND()
 {
        s3c24xx_nand_controller_t *s3c24xx_info;
 
        s3c24xx_info = malloc(sizeof(s3c24xx_nand_controller_t));
        if (s3c24xx_info == NULL) {
                LOG_ERROR("no memory for nand controller\n");
-               return NULL;
+               return -ENOMEM;
        }
 
        nand->controller_priv = s3c24xx_info;
        s3c24xx_info->target = get_target(args[1]);
        if (s3c24xx_info->target == NULL) {
                LOG_ERROR("target '%s' not defined", args[1]);
-               return NULL;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       return s3c24xx_info;
+       return ERROR_OK;
 }
 
 int s3c24xx_register_commands(struct command_context_s *cmd_ctx)
 
 #undef S3C2410_NFREG
 #define S3C2410_NFREG(x) ((x) + 0x4e000000)
 
-s3c24xx_nand_controller_t *s3c24xx_nand_device_command(
-                       struct command_context_s *cmd_ctx, char *cmd,
-                       char **args, int argc, struct nand_device_s *nand);
+#define S3C24XX_DEVICE_COMMAND() \
+               COMMAND_HELPER(s3c24xx_nand_device_command, \
+                               struct nand_device_s *nand, \
+                               s3c24xx_nand_controller_t **info)
+
+S3C24XX_DEVICE_COMMAND();
+
+#define CALL_S3C24XX_DEVICE_COMMAND(d, i) \
+       do { \
+               int retval = CALL_COMMAND_HANDLER(s3c24xx_nand_device_command, d, i); \
+               if (ERROR_OK != retval) \
+                       return retval; \
+       } while (0)
 
 int s3c24xx_register_commands(struct command_context_s *cmd_ctx);