You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/11/01 08:00:50 UTC

[GitHub] [incubator-nuttx] masayuki2009 commented on a diff in pull request #7472: Initialize global mutext/sem by NXMUTEX_INITIALIZER and SEM_INITIALIZER

masayuki2009 commented on code in PR #7472:
URL: https://github.com/apache/incubator-nuttx/pull/7472#discussion_r1010081631


##########
arch/arm/src/cxd56xx/cxd56_spi.c:
##########
@@ -179,15 +178,19 @@ static const struct spi_ops_s g_spi4ops =
 static struct cxd56_spidev_s g_spi4dev =
 {
   .spidev            =
-                        {
-                         &g_spi4ops
-                        },
+  {
+    .ops             = &g_spi4ops,
+  },
   .spibase           = CXD56_IMG_SPI_BASE,

Review Comment:
   @xiaoxiang781216 
   I think it would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/cxd56xx/cxd56_spi.c:
##########
@@ -264,15 +271,19 @@ static const struct spi_ops_s g_spi0ops =
 static struct cxd56_spidev_s g_spi0dev =
 {
   .spidev            =
-                        {
-                         &g_spi0ops
-                        },
+  {
+    .ops             = &g_spi0ops,
+  },
   .spibase           = CXD56_SPIM_BASE,

Review Comment:
   @xiaoxiang781216
   I think it would be better to move the style change to the 3rd commit.



##########
arch/arm/src/cxd56xx/cxd56_hostif.c:
##########
@@ -379,8 +382,6 @@ static int hif_initialize(struct hostif_buff_s *buffer)
 
   DEBUGASSERT(buffer);
 
-  memset(drv, 0, sizeof(struct cxd56_hifdrv_s));
-

Review Comment:
   @xiaoxiang781216 
   I think this change does not relate to the global mutex/sem initialization.
   



##########
arch/arm/src/cxd56xx/cxd56_spi.c:
##########
@@ -306,15 +317,19 @@ static const struct spi_ops_s g_spi3ops =
 static struct cxd56_spidev_s g_spi3dev =
 {
   .spidev            =
-                        {
-                         &g_spi3ops
-                        },
+  {
+    .ops             = &g_spi3ops,
+  },
   .spibase           = CXD56_SCU_SPI_BASE,

Review Comment:
   @xiaoxiang781216
   I think it would be better to move the style change to the 3rd commit.



##########
arch/arm/src/efm32/efm32_usbhost.c:
##########
@@ -5259,29 +5263,20 @@ static inline void efm32_sw_initialize(struct efm32_usbhost_s *priv)
 
   usbhost_devaddr_initialize(&priv->rhport);
 
-  /* Initialize semaphores & mutex */
-
-  nxsem_init(&priv->pscsem,  0, 0);
-  nxmutex_init(&priv->lock);
-
   /* Initialize the driver state data */
 
   priv->smstate   = SMSTATE_DETACHED;
   priv->connected = false;
   priv->change    = false;
 
-  /* Put all of the channels back in their initial, allocated state */
-
-  memset(priv->chan, 0, EFM32_MAX_TX_FIFOS * sizeof(struct efm32_chan_s));
-

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/rem initialization?
   



##########
arch/arm/src/cxd56xx/cxd56_emmc.c:
##########
@@ -932,17 +935,11 @@ static int cxd56_emmc_geometry(struct inode *inode,
 
 int cxd56_emmcinitialize(void)
 {
-  struct cxd56_emmc_state_s *priv;
+  struct cxd56_emmc_state_s *priv = &g_emmcdev;
   uint8_t *buf;
   struct emmc_dma_desc_s *descs;
   int ret;
 
-  priv = &g_emmcdev;
-

Review Comment:
   @xiaoxiang781216 
   I think this is a kind of style change.
   



##########
arch/arm/src/efm32/efm32_usbhost.c:
##########
@@ -5259,29 +5263,20 @@ static inline void efm32_sw_initialize(struct efm32_usbhost_s *priv)
 
   usbhost_devaddr_initialize(&priv->rhport);
 
-  /* Initialize semaphores & mutex */
-
-  nxsem_init(&priv->pscsem,  0, 0);
-  nxmutex_init(&priv->lock);
-
   /* Initialize the driver state data */
 
   priv->smstate   = SMSTATE_DETACHED;
   priv->connected = false;
   priv->change    = false;
 
-  /* Put all of the channels back in their initial, allocated state */
-
-  memset(priv->chan, 0, EFM32_MAX_TX_FIFOS * sizeof(struct efm32_chan_s));
-
   /* Initialize each channel */
 
   for (i = 0; i < EFM32_MAX_TX_FIFOS; i++)
     {
       struct efm32_chan_s *chan = &priv->chan[i];
 
       chan->chidx = i;
-      nxsem_init(&chan->waitsem,  0, 0);
+      nxsem_init(&chan->waitsem, 0, 0);
     }

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/cxd56xx/cxd56_spi.c:
##########
@@ -77,7 +77,6 @@ struct cxd56_spidev_s
   uint8_t          port;        /* Port number */
   int              initialized; /* Initialized flag */
 #ifdef CONFIG_CXD56_DMAC
-  bool             dmaenable;   /* Use DMA or not */
   DMA_HANDLE       rxdmach;     /* RX DMA channel handle */

Review Comment:
   @xiaoxiang781216 
   I don not think removing `dmaenable` does not relte to the global/mutex/sem initialization.
   



##########
arch/arm/src/imxrt/imxrt_flexspi.c:
##########
@@ -112,7 +112,8 @@ static struct imxrt_flexspidev_s g_flexspi0dev =
   {
     .ops = &g_flexspi0ops,
   },
-  .base = (struct flexspi_type_s *) IMXRT_FLEXSPIC_BASE,
+  .base = (struct flexspi_type_s *)IMXRT_FLEXSPIC_BASE,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/imxrt/imxrt_rtc_lowerhalf.c:
##########
@@ -128,7 +128,8 @@ static const struct rtc_ops_s g_rtc_ops =
 
 static struct imxrt_lowerhalf_s g_rtc_lowerhalf =
 {
-  .ops         = &g_rtc_ops,
+  .ops     = &g_rtc_ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/kinetis/kinetis_spi.c:
##########
@@ -221,12 +221,13 @@ static const struct spi_ops_s g_spi0ops =
 
 static struct kinetis_spidev_s g_spi0dev =
 {
-  .spidev            =
+  .spidev   =
   {
     &g_spi0ops
   },
-  .spibase           = KINETIS_SPI0_BASE,
-  .ctarsel           = KINETIS_SPI_CTAR0_OFFSET,
+  .spibase  = KINETIS_SPI0_BASE,
+  .lock     = NXMUTEX_INITIALIZER,
+  .ctarsel  = KINETIS_SPI_CTAR0_OFFSET,
 #ifdef CONFIG_KINETIS_SPI_DMA

Review Comment:
   @xiaoxiang781216 
   It would be better to moe the style changes to the 3rd commit.
   



##########
arch/arm/src/cxd56xx/cxd56_spi.c:
##########
@@ -222,15 +225,19 @@ static const struct spi_ops_s g_spi5ops =
 static struct cxd56_spidev_s g_spi5dev =
 {
   .spidev            =
-                        {
-                         &g_spi5ops
-                        },
+  {
+    .ops             = &g_spi5ops,
+  },

Review Comment:
   @xiaoxiang781216
   I think it would be better to move the style change to the 3rd commit.



##########
arch/arm/src/cxd56xx/cxd56_uart0.c:
##########
@@ -231,17 +231,7 @@ static ssize_t uart0_write(struct file *filep,
 
 int cxd56_uart0initialize(const char *devname)
 {
-  int ret;
-
-  nxmutex_init(&g_lock);
-
-  ret = register_driver(devname, &g_uart0fops, 0666, NULL);
-  if (ret != 0)
-    {
-      return ERROR;
-    }
-
-  return OK;
+  return register_driver(devname, &g_uart0fops, 0666, NULL);
 }

Review Comment:
   @xiaoxiang781216 
   Removing `nxmutex_init(&g_lock);` is OK to be included in the first commit.
   However, removing `ret` does not relate to the global mutex/sem initialization.
   



##########
arch/arm/src/kinetis/kinetis_usbhshost.c:
##########
@@ -5272,7 +5268,6 @@ struct usbhost_connection_s *kinetis_ehci_initialize(int controller)
    * port is reset (and enabled)."
    */
 
-  memset(&g_asynchead, 0, sizeof(struct kinetis_qh_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/cxd56xx/cxd56_spi.c:
##########
@@ -1201,14 +1216,6 @@ struct spi_dev_s *cxd56_spibus_initialize(int port)
   cxd56_spi_clock_enable(port);
   priv->spibasefreq = cxd56_get_spi_baseclock(port);
 
-  /* DMA settings */
-
-#ifdef CONFIG_CXD56_DMAC
-  priv->dmaenable = false;
-  priv->txdmach   = NULL;
-  priv->rxdmach   = NULL;
-#endif
-

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/cxd56xx/cxd56_hostif.c:
##########
@@ -441,11 +442,7 @@ static int hif_initialize(struct hostif_buff_s *buffer)
 
   cxd56_iccinit(CXD56_PROTO_HOSTIF);
 
-  nxsem_init(&drv->sync, 0, 0);
-
-  ret = cxd56_iccregisterhandler(CXD56_PROTO_HOSTIF, hif_rxhandler, NULL);
-
-  return ret;
+  return cxd56_iccregisterhandler(CXD56_PROTO_HOSTIF, hif_rxhandler, NULL);
 }

Review Comment:
   @xiaoxiang781216 
   I think this change does not relate to the global mutex/sem initialization.
   



##########
arch/arm/src/efm32/efm32_usbhost.c:
##########
@@ -484,14 +484,18 @@ static inline int efm32_hw_initialize(struct efm32_usbhost_s *priv);
  * single global instance.
  */
 
-static struct efm32_usbhost_s g_usbhost;
+static struct efm32_usbhost_s g_usbhost =
+{
+  .lock = NXMUTEX_INITIALIZER,
+  .pscsem = SEM_INITIALIZER(0),
+};
 
 /* This is the connection/enumeration interface */
 
 static struct usbhost_connection_s g_usbconn =
 {
-  .wait             = efm32_wait,
-  .enumerate        = efm32_enumerate,
+  .wait      = efm32_wait,
+  .enumerate = efm32_enumerate,
 };

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/cxd56xx/cxd56_spi.c:
##########
@@ -871,7 +886,7 @@ static void spi_exchange(struct spi_dev_s *dev, const void *txbuffer,
   size_t dmath = 0;
 #endif
 
-  if (priv->dmaenable && dmath < nwords)
+  if (priv->txdmach && priv->rxdmach && dmath < nwords)
     {

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/lpc17xx_40xx/lpc17_40_spi.c:
##########
@@ -139,9 +139,10 @@ static const struct spi_ops_s g_spiops =
 static struct lpc17_40_spidev_s g_spidev =
 {
   .spidev            =
-    {
-      &g_spiops
-    },
+  {
+    .ops             = &g_spiops,
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/lc823450/lc823450_usbdev.c:
##########
@@ -1722,14 +1720,13 @@ void usbdev_msc_read_enter()
   privep->epcmd &= ~USB_EPCMD_EMPTY_EN;
   epcmd_write(CONFIG_USBMSC_EPBULKIN, (privep->epcmd));
   lc823450_dmareauest_dir(g_hdma, DMA_REQUEST_USBDEV, 1);
-  nxsem_init(&dma_wait, 0, 0);
 }
 
 /****************************************************************************
  * Name: usbdev_msc_read_exit
  ****************************************************************************/
 
-void usbdev_msc_read_exit()
+void usbdev_msc_read_exit(void)

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/lc823450/lc823450_serial.c:
##########
@@ -1100,7 +1111,7 @@ static void uart_rxdma_callback(DMA_HANDLE hdma, void *arg, int result)
  * Name: up_hs_dmasetup
  ****************************************************************************/
 
-static void  up_hs_dmasetup()
+static void  up_hs_dmasetup(void)

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/lc823450/lc823450_spi.c:
##########
@@ -127,9 +127,15 @@ static const struct spi_ops_s g_spiops =
 static struct lc823450_spidev_s g_spidev =
 {
   .spidev            =
-    {
-      &g_spiops
-    },
+  {
+    .ops             = &g_spiops
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/lc823450/lc823450_spi.c:
##########
@@ -73,7 +73,7 @@ struct lc823450_spidev_s
 #endif
 #ifdef CONFIG_LC823450_SPI_DMA
   DMA_HANDLE       hdma;
-  sem_t dma_wait;
+  sem_t            dma_wait;

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/lpc17xx_40xx/lpc17_40_ssp.c:
##########
@@ -212,13 +213,14 @@ static const struct spi_ops_s g_spi1ops =
 static struct lpc17_40_sspdev_s g_ssp1dev =
 {
   .spidev            =
-    {
-      &g_spi1ops
-    },
+  {
+    .ops             = &g_spi1ops,
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/lpc17xx_40xx/lpc17_40_usbhost.c:
##########
@@ -3826,11 +3825,9 @@ struct usbhost_connection_s *lpc17_40_usbhost_initialize(int controller)
         LPC17_40_IOBUFFERS * CONFIG_LPC17_40_USBHOST_IOBUFSIZE);
 #endif
 
-  /* Initialize all the TDs, EDs and HCCA to 0 */
-
-  memset((void *)HCCA,   0, sizeof(struct ohci_hcca_s));
-  memset((void *)TDTAIL, 0, sizeof(struct ohci_gtd_s));
-  memset((void *)EDCTRL, 0, sizeof(struct lpc17_40_ed_s));

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/lpc17xx_40xx/lpc17_40_ssp.c:
##########
@@ -247,13 +249,14 @@ static const struct spi_ops_s g_spi2ops =
 static struct lpc17_40_sspdev_s g_ssp2dev =
 {
   .spidev            =
-    {
-      &g_spi2ops
-    },
+  {
+    .ops             = &g_spi2ops,
+  },
   .sspbase           = LPC17_40_SSP2_BASE,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/imx1/imx_spi.c:
##########
@@ -207,19 +207,23 @@ static struct imx_spidev_s g_spidev[] =
 {
 #ifdef CONFIG_IMX1_SPI1
   {
-    .ops  = &g_spiops,
-    .base = IMX_CSPI1_VBASE,
+    .ops     = &g_spiops,
+    .base    = IMX_CSPI1_VBASE,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/lpc17xx_40xx/lpc17_40_ssp.c:
##########
@@ -177,13 +177,14 @@ static const struct spi_ops_s g_spi0ops =
 static struct lpc17_40_sspdev_s g_ssp0dev =
 {
   .spidev            =
-    {
-      &g_spi0ops
-    },
+  {
+    .ops             = &g_spi0ops,
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/imxrt/imxrt_ehci.c:
##########
@@ -5202,7 +5202,6 @@ struct usbhost_connection_s *imxrt_ehci_initialize(int controller)
    * port is reset (and enabled)."
    */
 
-  memset(&g_asynchead, 0, sizeof(struct imxrt_qh_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/imx1/imx_spi.c:
##########
@@ -207,19 +207,23 @@ static struct imx_spidev_s g_spidev[] =
 {
 #ifdef CONFIG_IMX1_SPI1
   {
-    .ops  = &g_spiops,
-    .base = IMX_CSPI1_VBASE,
+    .ops     = &g_spiops,
+    .base    = IMX_CSPI1_VBASE,
+    .lock    = NXMUTEX_INITIALIZER,
 #ifndef CONFIG_SPI_POLLWAIT
-    .irq  = IMX_IRQ_CSPI1,
+    .waitsem = SEM_INITIALIZER(0),
+    .irq     = IMX_IRQ_CSPI1,
 #endif

Review Comment:
   @xiaoxiang781216 
   The line including `.irq` is a kind of style change.
   



##########
arch/arm/src/imxrt/imxrt_ehci.c:
##########
@@ -5225,7 +5224,6 @@ struct usbhost_connection_s *imxrt_ehci_initialize(int controller)
    * to point to the Interrupt Queue Head (g_intrhead).
    */
 
-  memset(&g_intrhead, 0, sizeof(struct imxrt_qh_s));

Review Comment:
   @xiaoxiang781216
   Does this change relate to the global mutex/sem initialization?



##########
arch/arm/src/imxrt/imxrt_ehci.c:
##########
@@ -5336,10 +5334,6 @@ struct usbhost_connection_s *imxrt_ehci_initialize(int controller)
 
   usbhost_vtrace1(EHCI_VTRACE1_INIITIALIZED, 0);
 
-  /* Initialize and return the connection interface */
-
-  g_ehciconn.wait = imxrt_wait;
-  g_ehciconn.enumerate = imxrt_enumerate;

Review Comment:
   @xiaoxiang781216
   Does this change relate to the global mutex/sem initialization?



##########
arch/arm/src/lpc2378/lpc23xx_spi.c:
##########
@@ -158,9 +158,10 @@ static const struct spi_ops_s g_spiops =
 static struct lpc23xx_spidev_s g_spidev =
 {
   .spidev            =
-    {
-      &g_spiops
-    },
+  {
+    .ops             = &g_spiops,
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/imxrt/imxrt_flexspi.c:
##########
@@ -606,8 +607,6 @@ void imxrt_flexspi_get_default_config(struct flexspi_config_s *config)
   config->ahb_config.ahb_grant_timeout_cycle  = 0xff;
   config->ahb_config.ahb_bus_timeout_cycle    = 0xffff;
   config->ahb_config.resume_wait_cycle        = 0x20;
-  memset(config->ahb_config.buffer, 0,
-         sizeof(config->ahb_config.buffer));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/imxrt/imxrt_lpspi.c:
##########
@@ -334,15 +340,18 @@ static struct imxrt_lpspidev_s g_lpspi3dev =
 {
   .spidev       =
   {
-    &g_spi3ops
+    .ops        = &g_spi3ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/gd32f4/gd32f4xx_spi.c:
##########
@@ -293,11 +293,12 @@ static uint8_t g_spi0_rxbuf[SPI0_DMA_BUFSIZE_ADJ] SPI_DMA_BUFEER_ALIGN;
 static struct gd32_spidev_s g_spi0dev =
 {
   .spidev   =
-              {
-               &g_spi0ops
-              },
+  {
+    .ops    = &g_spi0ops
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/imxrt/imxrt_lpspi.c:
##########
@@ -380,15 +389,18 @@ static struct imxrt_lpspidev_s g_lpspi4dev =
 {
   .spidev       =
   {
-    &g_spi4ops
+    .ops        = &g_spi4ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/kinetis/kinetis_edma.c:
##########
@@ -721,18 +707,12 @@ void weak_function arm_dma_initialize(void)
 
   /* Initialize data structures */
 
-  memset(&g_edma, 0, sizeof(struct kinetis_edma_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/kinetis/kinetis_spi.c:
##########
@@ -319,12 +325,13 @@ static const struct spi_ops_s g_spi2ops =
 
 static struct kinetis_spidev_s g_spi2dev =
 {
-  .spidev            =
+  .spidev   =
   {
     &g_spi2ops
   },
-  .spibase           = KINETIS_SPI2_BASE,
-  .ctarsel           = KINETIS_SPI_CTAR0_OFFSET,
+  .spibase  = KINETIS_SPI2_BASE,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/kinetis/kinetis_spi.c:
##########
@@ -270,12 +273,13 @@ static const struct spi_ops_s g_spi1ops =
 
 static struct kinetis_spidev_s g_spi1dev =
 {
-  .spidev            =
+  .spidev   =
   {
     &g_spi1ops
   },
-  .spibase           = KINETIS_SPI1_BASE,
-  .ctarsel           = KINETIS_SPI_CTAR0_OFFSET,
+  .spibase  = KINETIS_SPI1_BASE,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/imx1/imx_spi.c:
##########
@@ -207,19 +207,23 @@ static struct imx_spidev_s g_spidev[] =
 {
 #ifdef CONFIG_IMX1_SPI1
   {
-    .ops  = &g_spiops,
-    .base = IMX_CSPI1_VBASE,
+    .ops     = &g_spiops,
+    .base    = IMX_CSPI1_VBASE,
+    .lock    = NXMUTEX_INITIALIZER,
 #ifndef CONFIG_SPI_POLLWAIT
-    .irq  = IMX_IRQ_CSPI1,
+    .waitsem = SEM_INITIALIZER(0),
+    .irq     = IMX_IRQ_CSPI1,
 #endif
   },
 #endif
 #ifdef CONFIG_IMX1_SPI2
   {
-    .ops  = &g_spiops,
-    .base = IMX_CSPI2_VBASE,
+    .ops     = &g_spiops,
+    .base    = IMX_CSPI2_VBASE,
+    .lock    = NXMUTEX_INITIALIZER,
 #ifndef CONFIG_SPI_POLLWAIT
-    .irq  = IMX_IRQ_CSPI2,
+    .waitsem = SEM_INITIALIZER(0),
+    .irq     = IMX_IRQ_CSPI2,
 #endif

Review Comment:
   @xiaoxiang781216 
   The lines including `.ops`, `.base` and `.irq` are a kind of style changes.
   



##########
arch/arm/src/imxrt/imxrt_lpspi.c:
##########
@@ -242,15 +242,18 @@ static struct imxrt_lpspidev_s g_lpspi1dev =
 {
   .spidev       =
   {
-    &g_spi1ops
+    .ops        = &g_spi1ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/kinetis/kinetis_usbhshost.c:
##########
@@ -5295,7 +5290,6 @@ struct usbhost_connection_s *kinetis_ehci_initialize(int controller)
    * to point to the Interrupt Queue Head (g_intrhead).
    */
 
-  memset(&g_intrhead, 0, sizeof(struct kinetis_qh_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/kl/kl_spi.c:
##########
@@ -154,10 +155,11 @@ static const struct spi_ops_s g_spi1ops =
 static struct kl_spidev_s g_spi1dev =
 {
   .spidev            =
-    {
-      &g_spi1ops
-    },
+  {
+    .ops             = &g_spi1ops
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/kinetis/kinetis_usbhshost.c:
##########
@@ -5406,10 +5400,6 @@ struct usbhost_connection_s *kinetis_ehci_initialize(int controller)
 
   usbhost_vtrace1(EHCI_VTRACE1_INIITIALIZED, 0);
 
-  /* Initialize and return the connection interface */
-
-  g_ehciconn.wait = kinetis_wait;
-  g_ehciconn.enumerate = kinetis_enumerate;

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/kl/kl_spi.c:
##########
@@ -122,10 +122,11 @@ static const struct spi_ops_s g_spi0ops =
 static struct kl_spidev_s g_spi0dev =
 {
   .spidev            =
-    {
-      &g_spi0ops
-    },
+  {
+    .ops             = &g_spi0ops
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit
   



##########
arch/arm/src/lc823450/lc823450_dma.c:
##########
@@ -303,7 +306,7 @@ static void dma_done(DMA_HANDLE handle, void *arg, int result)
   test_done = 1;
 }
 
-void lc823450_dma_test()
+void lc823450_dma_test(void)

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/lpc31xx/lpc31_ehci.c:
##########
@@ -5279,7 +5279,6 @@ struct usbhost_connection_s *lpc31_ehci_initialize(int controller)
    *  first port is reset (and enabled)."
    */
 
-  memset(&g_asynchead, 0, sizeof(struct lpc31_qh_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/lpc31xx/lpc31_ehci.c:
##########
@@ -5303,7 +5302,6 @@ struct usbhost_connection_s *lpc31_ehci_initialize(int controller)
    * Head (g_intrhead).
    */
 
-  memset(&g_intrhead, 0, sizeof(struct lpc31_qh_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/lpc31xx/lpc31_ehci.c:
##########
@@ -5440,10 +5438,6 @@ struct usbhost_connection_s *lpc31_ehci_initialize(int controller)
   up_enable_irq(LPC31_IRQ_USBOTG); /* enable USB interrupt */
   usbhost_vtrace1(EHCI_VTRACE1_INIITIALIZED, 0);
 
-  /* Initialize and return the connection interface */
-
-  g_ehciconn.wait      = lpc31_wait;
-  g_ehciconn.enumerate = lpc31_enumerate;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/lpc31xx/lpc31_spi.c:
##########
@@ -154,9 +154,10 @@ static const struct spi_ops_s g_spiops =
 static struct lpc31_spidev_s g_spidev =
 {
   .spidev            =
-    {
-      &g_spiops
-    },
+  {
+    .ops             = &g_spiops,
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/lpc43xx/lpc43_ehci.c:
##########
@@ -5240,10 +5238,6 @@ struct usbhost_connection_s *lpc43_ehci_initialize(int controller)
   up_enable_irq(LPC43M4_IRQ_USB0); /* enable USB interrupt */
   usbhost_vtrace1(EHCI_VTRACE1_INIITIALIZED, 0);
 
-  /* Initialize and return the connection interface */
-
-  g_ehciconn.wait      = lpc43_wait;
-  g_ehciconn.enumerate = lpc43_enumerate;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/lpc43xx/lpc43_spi.c:
##########
@@ -130,9 +130,10 @@ static const struct spi_ops_s g_spiops =
 static struct lpc43_spidev_s g_spidev =
 {
   .spidev            =
-    {
-      &g_spiops
-    },
+  {
+    .ops             = &g_spiops,
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/lpc43xx/lpc43_ehci.c:
##########
@@ -5108,7 +5107,6 @@ struct usbhost_connection_s *lpc43_ehci_initialize(int controller)
    * Head (g_intrhead).
    */
 
-  memset(&g_intrhead, 0, sizeof(struct lpc43_qh_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/lpc43xx/lpc43_ssp.c:
##########
@@ -144,14 +144,15 @@ static const struct spi_ops_s g_spi0ops =
 static struct lpc43_sspdev_s g_ssp0dev =
 {
   .spidev            =
-    {
-      &g_spi0ops
-    },
+  {
+    .ops             = &g_spi0ops,
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/lpc43xx/lpc43_ehci.c:
##########
@@ -5087,7 +5087,6 @@ struct usbhost_connection_s *lpc43_ehci_initialize(int controller)
    *  first port is reset (and enabled)."
    */
 
-  memset(&g_asynchead, 0, sizeof(struct lpc43_qh_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/lpc43xx/lpc43_ssp.c:
##########
@@ -184,14 +185,15 @@ static const struct spi_ops_s g_spi1ops =
 static struct lpc43_sspdev_s g_ssp1dev =
 {
   .spidev            =
-    {
-      &g_spi1ops
-    },
+  {
+    .ops             = &g_spi1ops,
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/lpc54xx/lpc54_rtc_lowerhalf.c:
##########
@@ -145,7 +145,8 @@ static const struct rtc_ops_s g_rtc_ops =
 
 static struct lpc54_lowerhalf_s g_rtc_lowerhalf =
 {
-  .ops           = &g_rtc_ops,
+  .ops     = &g_rtc_ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/lpc54xx/lpc54_usb0_ohci.c:
##########
@@ -3904,11 +3903,9 @@ struct usbhost_connection_s *lpc54_usbhost_initialize(int controller)
         LPC54_IOFREE_BASE, LPC54_IOBUFFERS * CONFIG_LPC54_OHCI_IOBUFSIZE);
 #endif
 
-  /* Initialize all the TDs, EDs and HCCA to 0 */
-
-  memset((void *)HCCA,   0, sizeof(struct ohci_hcca_s));
-  memset((void *)TDTAIL, 0, sizeof(struct ohci_gtd_s));
-  memset((void *)EDCTRL, 0, sizeof(struct lpc54_ed_s));

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/nrf52/nrf52_radio.c:
##########
@@ -1149,22 +1151,11 @@ nrf52_radio_initialize(int intf, struct nrf52_radio_board_s *board)
         }
     }
 
-  /* Reset some data */
-
-  memset(&dev->pktcfg, 0, sizeof(struct nrf52_radio_pktcfg_s));
-  memset(dev->rxbuf, 0, NRF52_RADIO_RXBUFFER);
-  memset(dev->txbuf, 0, NRF52_RADIO_TXBUFFER);

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/nrf52/nrf52_spi.c:
##########
@@ -198,11 +198,13 @@ static struct nrf52_spidev_s g_spi0dev =
 {
   .spidev    =
   {
-    &g_spi0ops
+    .ops     = &g_spi0ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c:
##########
@@ -151,7 +151,8 @@ static const struct rtc_ops_s g_rtc_ops =
 
 static struct max326_lowerhalf_s g_rtc_lowerhalf =
 {
-  .ops        = &g_rtc_ops,
+  .ops     = &g_rtc_ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/max326xx/max32660/max32660_spim.c:
##########
@@ -232,10 +232,11 @@ static const struct spi_ops_s g_sp0iops =
 static struct max326_spidev_s g_spi0dev =
 {
   .dev      =
-    {
-      &g_sp0iops
-    },
+  {
+    .ops    = &g_sp0iops,
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/nrf52/nrf52_rng.c:
##########
@@ -124,13 +128,6 @@ static int nrf52_rng_initialize(void)
 
   first_flag = false;
 
-  _info("Initializing RNG\n");
-
-  memset(&g_rngdev, 0, sizeof(struct rng_dev_s));

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/nrf52/nrf52_spi.c:
##########
@@ -249,11 +251,13 @@ static struct nrf52_spidev_s g_spi1dev =
 {
   .spidev    =
   {
-    &g_spi1ops
+    .ops     = &g_spi1ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/nrf52/nrf52_spi.c:
##########
@@ -300,11 +304,13 @@ static struct nrf52_spidev_s g_spi2dev =
 {
   .spidev    =
   {
-    &g_spi2ops
+    .ops     = &g_spi2ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/rp2040/rp2040_flash_mtd.c:
##########
@@ -165,10 +165,11 @@ static struct rp2040_flash_dev_s my_dev =
 #endif
       rp2040_flash_ioctl,
       "rp_flash"
-    }
+  },
+  .lock = NXMUTEX_INITIALIZER,
 };
 
-static bool initialized = false;
+static bool initialized;

Review Comment:
   @xiaoxiang781216 
   Do this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/rp2040/rp2040_spi.c:
##########
@@ -222,15 +226,19 @@ static const struct spi_ops_s g_spi1ops =
 static struct rp2040_spidev_s g_spi1dev =
 {
   .spidev            =
-                        {
-                          &g_spi1ops
-                        },
+  {
+    .ops             = &g_spi1ops,
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/s32k1xx/s32k1xx_lpspi.c:
##########
@@ -255,12 +255,13 @@ static struct s32k1xx_lpspidev_s g_lpspi0dev =
 {
   .spidev       =
   {
-    &g_spi0ops
+    .ops        = &g_spi0ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/s32k1xx/s32k1xx_edma.c:
##########
@@ -706,18 +692,12 @@ void weak_function arm_dma_initialize(void)
 
   /* Initialize data structures */
 
-  memset(&g_edma, 0, sizeof(struct s32k1xx_edma_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/s32k1xx/s32k1xx_edma.c:
##########
@@ -215,7 +201,7 @@ static struct s32k1xx_edmatcd_s *s32k1xx_tcd_alloc(void)
    */
 
   flags = enter_critical_section();
-  s32k1xx_takedsem();
+  nxsem_wait_uninterruptible(&g_edma.dsem);

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/rp2040/rp2040_spi.c:
##########
@@ -177,15 +177,19 @@ static const struct spi_ops_s g_spi0ops =
 static struct rp2040_spidev_s g_spi0dev =
 {
   .spidev            =
-                        {
-                          &g_spi0ops
-                        },
+  {
+    .ops             = &g_spi0ops,
+  },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/s32k1xx/s32k1xx_edma.c:
##########
@@ -247,7 +233,7 @@ static void s32k1xx_tcd_free(struct s32k1xx_edmatcd_s *tcd)
 
   flags = spin_lock_irqsave(NULL);
   sq_addlast((sq_entry_t *)tcd, &g_tcd_free);
-  s32k1xx_givedsem();
+  nxsem_post(&g_edma.dsem);

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/s32k1xx/s32k1xx_edma.c:
##########
@@ -172,26 +178,6 @@ static struct s32k1xx_edmatcd_s g_tcd_pool[CONFIG_S32K1XX_EDMA_NTCD]
  * Private Functions
  ****************************************************************************/
 
-/****************************************************************************
- * Name: s32k1xx_takedsem() and s32k1xx_givedsem()
- *
- * Description:
- *   Used to wait for availability of descriptors in the descriptor table.
- *
- ****************************************************************************/
-
-#if CONFIG_S32K1XX_EDMA_NTCD > 0
-static void s32k1xx_takedsem(void)
-{
-  nxsem_wait_uninterruptible(&g_edma.dsem);
-}
-
-static inline void s32k1xx_givedsem(void)
-{
-  nxsem_post(&g_edma.dsem);
-}
-#endif
-

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/s32k1xx/s32k1xx_lpspi.c:
##########
@@ -305,12 +306,13 @@ static struct s32k1xx_lpspidev_s g_lpspi1dev =
 {
   .spidev       =
   {
-    &g_spi1ops
+    .ops        = &g_spi1ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/s32k1xx/s32k1xx_lpspi.c:
##########
@@ -355,12 +357,13 @@ static struct s32k1xx_lpspidev_s g_lpspi2dev =
 {
   .spidev       =
   {
-    &g_spi2ops
+    .ops        = &g_spi2ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/s32k3xx/s32k3xx_edma.c:
##########
@@ -416,26 +422,6 @@ const struct peripheral_clock_config_s edma_clockconfig[] =
  * Private Functions
  ****************************************************************************/
 
-/****************************************************************************
- * Name: s32k3xx_takedsem() and s32k3xx_givedsem()
- *
- * Description:
- *   Used to wait for availability of descriptors in the descriptor table.
- *
- ****************************************************************************/
-
-#if CONFIG_S32K3XX_EDMA_NTCD > 0
-static void s32k3xx_takedsem(void)
-{
-  nxsem_wait_uninterruptible(&g_edma.dsem);
-}
-
-static inline void s32k3xx_givedsem(void)
-{
-  nxsem_post(&g_edma.dsem);
-}
-#endif
-

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/s32k3xx/s32k3xx_edma.c:
##########
@@ -916,18 +902,12 @@ void weak_function arm_dma_initialize(void)
 
   /* Initialize data structures */
 
-  memset(&g_edma, 0, sizeof(struct s32k3xx_edma_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/s32k3xx/s32k3xx_lpspi.c:
##########
@@ -246,15 +246,18 @@ static struct s32k3xx_lpspidev_s g_lpspi0dev =
 {
   .spidev       =
   {
-    &g_spi0ops
+    .ops        = &g_spi0ops,
   },

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/s32k3xx/s32k3xx_lpspi.c:
##########
@@ -293,15 +296,18 @@ static struct s32k3xx_lpspidev_s g_lpspi1dev =
 {
   .spidev       =
   {
-    &g_spi1ops
+    .ops        = &g_spi1ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/s32k3xx/s32k3xx_lpspi.c:
##########
@@ -340,15 +346,18 @@ static struct s32k3xx_lpspidev_s g_lpspi2dev =
 {
   .spidev       =
   {
-    &g_spi2ops
+    .ops        = &g_spi2ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/s32k3xx/s32k3xx_edma.c:
##########
@@ -491,7 +477,7 @@ static void s32k3xx_tcd_free(struct s32k3xx_edmatcd_s *tcd)
 
   flags = spin_lock_irqsave(NULL);
   sq_addlast((sq_entry_t *)tcd, &g_tcd_free);
-  s32k3xx_givedsem();
+  nxsem_post(&g_edma.dsem);

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/s32k3xx/s32k3xx_lpspi.c:
##########
@@ -434,15 +446,18 @@ static struct s32k3xx_lpspidev_s g_lpspi4dev =
 {
   .spidev       =
   {
-    &g_spi4ops
+    .ops        = &g_spi4ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/sam34/sam_aes.c:
##########
@@ -59,8 +59,8 @@
  * Private Data
  ****************************************************************************/
 
-static mutex_t g_samaes_lock;
-static bool    g_samaes_initdone = false;

Review Comment:
   @xiaoxiang781216 
   Does this change (removing `= false`) relate to the global mutex/sem initialization?
   



##########
arch/arm/src/s32k3xx/s32k3xx_edma.c:
##########
@@ -459,7 +445,7 @@ static struct s32k3xx_edmatcd_s *s32k3xx_tcd_alloc(void)
    */
 
   flags = enter_critical_section();
-  s32k3xx_takedsem();
+  nxsem_wait_uninterruptible(&g_edma.dsem);

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/s32k3xx/s32k3xx_lpspi.c:
##########
@@ -387,15 +396,18 @@ static struct s32k3xx_lpspidev_s g_lpspi3dev =
 {
   .spidev       =
   {
-    &g_spi3ops
+    .ops        = &g_spi3ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/s32k3xx/s32k3xx_qspi.c:
##########
@@ -221,19 +221,23 @@ static const struct qspi_ops_s g_qspi0ops =
 
 static struct s32k3xx_qspidev_s g_qspi0dev =
 {
-  .qspi            =
+  .qspi              =

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/sam34/sam_spi.c:
##########
@@ -1857,12 +1859,7 @@ struct spi_dev_s *sam_spibus_initialize(int port)
       spi_getreg(spi, SAM_SPI_SR_OFFSET);
       spi_getreg(spi, SAM_SPI_RDR_OFFSET);
 
-      /* Initialize the SPI mutex that enforces mutually exclusive
-       * access to the SPI registers.
-       */
-
-      nxmutex_init(&spi->spilock);
-      spi->initialized = true;
+       spi->initialized = true;

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/sam34/sam_twi.c:
##########
@@ -725,7 +747,7 @@ static int twi_transfer(struct i2c_master_s *dev,
  ****************************************************************************/
 
 #ifdef CONFIG_I2C_RESET
-static int twi_reset(struct i2c_master_s * dev)
+static int twi_reset(struct i2c_master_s *dev)

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/sam34/sam_twi.c:
##########
@@ -917,12 +934,7 @@ struct i2c_master_s *sam_i2cbus_initialize(int bus)
 #ifdef CONFIG_SAM34_TWIM1
   if (bus == 1)
     {
-      /* Set up TWI1 register base address and IRQ number */
-
-      priv       = &g_twi1;
-      priv->base = SAM_TWI1_BASE;
-      priv->irq  = SAM_IRQ_TWI1;
-      priv->twi  = 1;
+      priv = &g_twi1;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sam34/sam_twi.c:
##########
@@ -891,12 +913,7 @@ struct i2c_master_s *sam_i2cbus_initialize(int bus)
 #ifdef CONFIG_SAM34_TWIM0
   if (bus == 0)
     {
-      /* Set up TWI0 register base address and IRQ number */
-
-      priv       = &g_twi0;
-      priv->base = SAM_TWI0_BASE;
-      priv->irq  = SAM_IRQ_TWI0;
-      priv->twi  = 0;
+      priv = &g_twi0;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sam34/sam_twi.c:
##########
@@ -187,14 +187,6 @@ static void twi_hw_initialize(struct twi_dev_s *priv, unsigned int pid,
  * Private Data
  ****************************************************************************/
 
-#ifdef CONFIG_SAM34_TWIM0
-static struct twi_dev_s g_twi0;
-#endif
-
-#ifdef CONFIG_SAM34_TWIM1
-static struct twi_dev_s g_twi1;
-#endif
-

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/s32k3xx/s32k3xx_lpspi.c:
##########
@@ -481,15 +496,18 @@ static struct s32k3xx_lpspidev_s g_lpspi5dev =
 {
   .spidev       =
   {
-    &g_spi5ops
+    .ops        = &g_spi5ops,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/sam34/sam_twi.c:
##########
@@ -946,15 +958,6 @@ struct i2c_master_s *sam_i2cbus_initialize(int bus)
       return NULL;
     }
 
-  /* Initialize the device structure */
-
-  priv->dev.ops = &g_twiops;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_adc.c:
##########
@@ -2041,17 +2050,9 @@ struct adc_dev_s *sam_adc_initialize(void)
       /* Initialize the public ADC device data structure */
 
 #ifdef SAMA5_ADC_HAVE_CHANNELS
-      g_adcdev.ad_ops  = &g_adcops;
       priv->dev = &g_adcdev;
 #endif
 
-      g_adcdev.ad_priv = priv;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sam34/sam_twi.c:
##########
@@ -979,21 +982,16 @@ struct i2c_master_s *sam_i2cbus_initialize(int bus)
  *
  ****************************************************************************/
 
-int sam_i2cbus_uninitialize(struct i2c_master_s * dev)
+int sam_i2cbus_uninitialize(struct i2c_master_s *dev)
 {
-  struct twi_dev_s *priv = (struct twi_dev_s *) dev;
+  struct twi_dev_s *priv = (struct twi_dev_s *)dev;
 

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/sama5/sam_adc.c:
##########
@@ -497,11 +497,20 @@ static const struct adc_ops_s g_adcops =
 
 /* ADC internal state */
 
-static struct sam_adc_s g_adcpriv;
+static struct sam_adc_s g_adcpriv =
+{
+  .lock        = NXMUTEX_INITIALIZER,
+};
 
 /* ADC device instance */
 
-static struct adc_dev_s g_adcdev;
+static struct adc_dev_s g_adcdev =
+{
+#ifdef SAMA5_ADC_HAVE_CHANNELS
+  .ad_ops      = &g_adcops,
+#endif
+  .ad_priv     = &g_adcpriv,
+};

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_can.c:
##########
@@ -1926,9 +1942,8 @@ struct can_dev_s *sam_caninitialize(int port)
     {
       /* Select the CAN1 device structure */
 
-      dev    = &g_can1dev;
-      priv   = &g_can1priv;
-      config = &g_can1const;
+      dev  = &g_can1dev;
+      priv = &g_can1priv;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_can.c:
##########
@@ -287,8 +287,17 @@ static const struct sam_config_s g_can0const =
   },
 };
 
-static struct sam_can_s g_can0priv;
-static struct can_dev_s g_can0dev;
+static struct sam_can_s g_can0priv =
+{
+  .config           = &g_can0const,
+  .freemb           = CAN_ALL_MAILBOXES,
+  .lock             = NXMUTEX_INITIALIZER,
+};
+static struct can_dev_s g_can0dev =
+{
+  .cd_ops           = &g_canops,
+  .cd_priv          = &g_can0priv,
+};

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_can.c:
##########
@@ -322,8 +331,17 @@ static const struct sam_config_s g_can1const =
   },
 };
 
-static struct sam_can_s g_can1priv;
-static struct can_dev_s g_can1dev;
+static struct sam_can_s g_can1priv =
+{
+  .config           = &g_can1const,
+  .freemb           = CAN_ALL_MAILBOXES,
+  .lock             = NXMUTEX_INITIALIZER,
+};
+static struct can_dev_s g_can1dev =
+{
+  .cd_ops           = &g_canops,
+  .cd_priv          = &g_can1priv,
+};

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_can.c:
##########
@@ -1943,16 +1958,8 @@ struct can_dev_s *sam_caninitialize(int port)
     {
       /* Yes, then perform one time data initialization */
 
-      memset(priv, 0, sizeof(struct sam_can_s));
-      priv->config      = config;
-      priv->freemb      = CAN_ALL_MAILBOXES;
       priv->initialized = true;
 
-      nxmutex_init(&priv->lock);
-
-      dev->cd_ops       = &g_canops;
-      dev->cd_priv      = (void *)priv;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_adc.c:
##########
@@ -2041,17 +2050,9 @@ struct adc_dev_s *sam_adc_initialize(void)
       /* Initialize the public ADC device data structure */
 
 #ifdef SAMA5_ADC_HAVE_CHANNELS
-      g_adcdev.ad_ops  = &g_adcops;
       priv->dev = &g_adcdev;
 #endif
 
-      g_adcdev.ad_priv = priv;
-
-      /* Initialize the private ADC device data structure */
-
-      nxmutex_init(&priv->lock);
-      priv->cb  = NULL;

Review Comment:
   @xiaoxiang781216 
   Does this change (removing `priv->cb = NULL`) relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_can.c:
##########
@@ -1902,7 +1920,6 @@ struct can_dev_s *sam_caninitialize(int port)
 {
   struct can_dev_s *dev;
   struct sam_can_s *priv;
-  const struct sam_config_s *config;

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_dmac.c:
##########
@@ -1334,7 +1322,7 @@ sam_allocdesc(struct sam_dmach_s *dmach, struct dma_linklist_s *prev,
        * there is at least one free descriptor in the table and it is ours.
        */
 
-      ret = sam_takedsem(dmac);
+      ret = nxsem_wait_uninterruptible(&dmac->dsem);

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_can.c:
##########
@@ -1915,9 +1932,8 @@ struct can_dev_s *sam_caninitialize(int port)
     {
       /* Select the CAN0 device structure */
 
-      dev    = &g_can0dev;
-      priv   = &g_can0priv;
-      config = &g_can0const;
+      dev  = &g_can0dev;
+      priv = &g_can0priv;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_can.c:
##########
@@ -1943,16 +1958,8 @@ struct can_dev_s *sam_caninitialize(int port)
     {
       /* Yes, then perform one time data initialization */
 
-      memset(priv, 0, sizeof(struct sam_can_s));
-      priv->config      = config;
-      priv->freemb      = CAN_ALL_MAILBOXES;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_ehci.c:
##########
@@ -5044,7 +5043,6 @@ struct usbhost_connection_s *sam_ehci_initialize(int controller)
    * Head (g_intrhead).
    */
 
-  memset(&g_intrhead, 0, sizeof(struct sam_qh_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_dmac.c:
##########
@@ -1471,7 +1459,7 @@ static void sam_freelinklist(struct sam_dmach_s *dmach)
        */
 
       memset(desc, 0, sizeof(struct dma_linklist_s));
-      sam_givedsem(dmac);
+      nxsem_post(&dmac->dsem);

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_dmac.c:
##########
@@ -463,24 +469,6 @@ static struct sam_dmac_s g_dmac1 =
  * Private Functions
  ****************************************************************************/
 
-/****************************************************************************
- * Name: sam_takedsem() and sam_givedsem()
- *
- * Description:
- *   Used to wait for availability of descriptors in the descriptor table.
- *
- ****************************************************************************/
-
-static int sam_takedsem(struct sam_dmac_s *dmac)
-{
-  return nxsem_wait_uninterruptible(&dmac->dsem);
-}
-
-static inline void sam_givedsem(struct sam_dmac_s *dmac)
-{
-  nxsem_post(&dmac->dsem);
-}
-

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_ehci.c:
##########
@@ -5020,7 +5020,6 @@ struct usbhost_connection_s *sam_ehci_initialize(int controller)
    *  first port is reset (and enabled)."
    */
 
-  memset(&g_asynchead, 0, sizeof(struct sam_qh_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_dmac.c:
##########
@@ -1349,7 +1337,7 @@ sam_allocdesc(struct sam_dmach_s *dmach, struct dma_linklist_s *prev,
       ret = nxmutex_lock(&dmac->chlock);
       if (ret < 0)
         {
-          sam_givedsem(dmac);
+          nxsem_post(&dmac->dsem);

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_ehci.c:
##########
@@ -435,11 +435,20 @@ static int sam_reset(void);
  * global instance.
  */
 
-static struct sam_ehci_s g_ehci;
+static struct sam_ehci_s g_ehci =
+{
+  .lock = NXMUTEX_INITIALIZER,
+  .pscsem = SEM_INITIALIZER(0),
+  .ep0.iocsem = SEM_INITIALIZER(1),
+};
 
 /* This is the connection/enumeration interface */
 
-static struct usbhost_connection_s g_ehciconn;
+static struct usbhost_connection_s g_ehciconn =
+{
+  .wait = sam_wait,
+  .enumerate = sam_enumerate,
+};

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_ehci.c:
##########
@@ -5181,10 +5179,6 @@ struct usbhost_connection_s *sam_ehci_initialize(int controller)
   up_enable_irq(SAM_IRQ_UHPHS); /* enable USB interrupt */
   usbhost_vtrace1(EHCI_VTRACE1_INIITIALIZED, 0);
 
-  /* Initialize and return the connection interface */
-
-  g_ehciconn.wait      = sam_wait;
-  g_ehciconn.enumerate = sam_enumerate;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_hsmci.c:
##########
@@ -596,57 +596,145 @@ static void sam_callback(void *arg);
  * Private Data
  ****************************************************************************/
 
-/* Callbacks */
+/* Pre-allocate memory for each HSMCI device */
 
-static const struct sdio_dev_s g_callbacks =
+#ifdef CONFIG_SAMA5_HSMCI0
+static struct sam_dev_s g_hsmci0 =
 {
-  .reset            = sam_reset,
-  .capabilities     = sam_capabilities,
-  .status           = sam_status,
-  .widebus          = sam_widebus,
-  .clock            = sam_clock,
-  .attach           = sam_attach,
-  .sendcmd          = sam_sendcmd,
-  .blocksetup       = sam_blocksetup,
-  .recvsetup        = sam_recvsetup,
-  .sendsetup        = sam_sendsetup,
-  .cancel           = sam_cancel,
-  .waitresponse     = sam_waitresponse,
-  .recv_r1          = sam_recvshort,
-  .recv_r2          = sam_recvlong,
-  .recv_r3          = sam_recvshort,
-  .recv_r4          = sam_recvnotimpl,
-  .recv_r5          = sam_recvnotimpl,
-  .recv_r6          = sam_recvshort,
-  .recv_r7          = sam_recvshort,
-  .waitenable       = sam_waitenable,
-  .eventwait        = sam_eventwait,
-  .callbackenable   = sam_callbackenable,
-  .registercallback = sam_registercallback,
+  .dev                =
+  {
+    .reset            = sam_reset,
+    .capabilities     = sam_capabilities,
+    .status           = sam_status,
+    .widebus          = sam_widebus,
+    .clock            = sam_clock,
+    .attach           = sam_attach,
+    .sendcmd          = sam_sendcmd,
+    .blocksetup       = sam_blocksetup,
+    .recvsetup        = sam_recvsetup,
+    .sendsetup        = sam_sendsetup,
+    .cancel           = sam_cancel,
+    .waitresponse     = sam_waitresponse,
+    .recv_r1          = sam_recvshort,
+    .recv_r2          = sam_recvlong,
+    .recv_r3          = sam_recvshort,
+    .recv_r4          = sam_recvnotimpl,
+    .recv_r5          = sam_recvnotimpl,
+    .recv_r6          = sam_recvshort,
+    .recv_r7          = sam_recvshort,
+    .waitenable       = sam_waitenable,
+    .eventwait        = sam_eventwait,
+    .callbackenable   = sam_callbackenable,
+    .registercallback = sam_registercallback,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/sama5/sam_hsmci.c:
##########
@@ -596,57 +596,145 @@ static void sam_callback(void *arg);
  * Private Data
  ****************************************************************************/
 
-/* Callbacks */
+/* Pre-allocate memory for each HSMCI device */
 
-static const struct sdio_dev_s g_callbacks =
+#ifdef CONFIG_SAMA5_HSMCI0
+static struct sam_dev_s g_hsmci0 =
 {
-  .reset            = sam_reset,
-  .capabilities     = sam_capabilities,
-  .status           = sam_status,
-  .widebus          = sam_widebus,
-  .clock            = sam_clock,
-  .attach           = sam_attach,
-  .sendcmd          = sam_sendcmd,
-  .blocksetup       = sam_blocksetup,
-  .recvsetup        = sam_recvsetup,
-  .sendsetup        = sam_sendsetup,
-  .cancel           = sam_cancel,
-  .waitresponse     = sam_waitresponse,
-  .recv_r1          = sam_recvshort,
-  .recv_r2          = sam_recvlong,
-  .recv_r3          = sam_recvshort,
-  .recv_r4          = sam_recvnotimpl,
-  .recv_r5          = sam_recvnotimpl,
-  .recv_r6          = sam_recvshort,
-  .recv_r7          = sam_recvshort,
-  .waitenable       = sam_waitenable,
-  .eventwait        = sam_eventwait,
-  .callbackenable   = sam_callbackenable,
-  .registercallback = sam_registercallback,
+  .dev                =
+  {
+    .reset            = sam_reset,
+    .capabilities     = sam_capabilities,
+    .status           = sam_status,
+    .widebus          = sam_widebus,
+    .clock            = sam_clock,
+    .attach           = sam_attach,
+    .sendcmd          = sam_sendcmd,
+    .blocksetup       = sam_blocksetup,
+    .recvsetup        = sam_recvsetup,
+    .sendsetup        = sam_sendsetup,
+    .cancel           = sam_cancel,
+    .waitresponse     = sam_waitresponse,
+    .recv_r1          = sam_recvshort,
+    .recv_r2          = sam_recvlong,
+    .recv_r3          = sam_recvshort,
+    .recv_r4          = sam_recvnotimpl,
+    .recv_r5          = sam_recvnotimpl,
+    .recv_r6          = sam_recvshort,
+    .recv_r7          = sam_recvshort,
+    .waitenable       = sam_waitenable,
+    .eventwait        = sam_eventwait,
+    .callbackenable   = sam_callbackenable,
+    .registercallback = sam_registercallback,
 #ifdef CONFIG_SDIO_DMA
 #ifndef HSCMI_NORXDMA
-  .dmarecvsetup     = sam_dmarecvsetup,
+    .dmarecvsetup     = sam_dmarecvsetup,
 #else
-  .dmarecvsetup     = sam_recvsetup,
+    .dmarecvsetup     = sam_recvsetup,
 #endif
 #ifndef HSCMI_NOTXDMA
-  .dmasendsetup     = sam_dmasendsetup,
+    .dmasendsetup     = sam_dmasendsetup,
 #else
-  .dmasendsetup     = sam_sendsetup,
+    .dmasendsetup     = sam_sendsetup,
 #endif
 #endif
+  },
+  .waitsem            = SEM_INITIALIZER(0),
+  .base               = SAM_HSMCI0_VBASE,
+  .hsmci              = 0,

Review Comment:
   @xiaoxiang781216 
   Do these changes (adding `.base` and `.hsmci`) relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_hsmci.c:
##########
@@ -596,57 +596,145 @@ static void sam_callback(void *arg);
  * Private Data
  ****************************************************************************/
 
-/* Callbacks */
+/* Pre-allocate memory for each HSMCI device */
 
-static const struct sdio_dev_s g_callbacks =
+#ifdef CONFIG_SAMA5_HSMCI0
+static struct sam_dev_s g_hsmci0 =
 {
-  .reset            = sam_reset,
-  .capabilities     = sam_capabilities,
-  .status           = sam_status,
-  .widebus          = sam_widebus,
-  .clock            = sam_clock,
-  .attach           = sam_attach,
-  .sendcmd          = sam_sendcmd,
-  .blocksetup       = sam_blocksetup,
-  .recvsetup        = sam_recvsetup,
-  .sendsetup        = sam_sendsetup,
-  .cancel           = sam_cancel,
-  .waitresponse     = sam_waitresponse,
-  .recv_r1          = sam_recvshort,
-  .recv_r2          = sam_recvlong,
-  .recv_r3          = sam_recvshort,
-  .recv_r4          = sam_recvnotimpl,
-  .recv_r5          = sam_recvnotimpl,
-  .recv_r6          = sam_recvshort,
-  .recv_r7          = sam_recvshort,
-  .waitenable       = sam_waitenable,
-  .eventwait        = sam_eventwait,
-  .callbackenable   = sam_callbackenable,
-  .registercallback = sam_registercallback,
+  .dev                =
+  {
+    .reset            = sam_reset,
+    .capabilities     = sam_capabilities,
+    .status           = sam_status,
+    .widebus          = sam_widebus,
+    .clock            = sam_clock,
+    .attach           = sam_attach,
+    .sendcmd          = sam_sendcmd,
+    .blocksetup       = sam_blocksetup,
+    .recvsetup        = sam_recvsetup,
+    .sendsetup        = sam_sendsetup,
+    .cancel           = sam_cancel,
+    .waitresponse     = sam_waitresponse,
+    .recv_r1          = sam_recvshort,
+    .recv_r2          = sam_recvlong,
+    .recv_r3          = sam_recvshort,
+    .recv_r4          = sam_recvnotimpl,
+    .recv_r5          = sam_recvnotimpl,
+    .recv_r6          = sam_recvshort,
+    .recv_r7          = sam_recvshort,
+    .waitenable       = sam_waitenable,
+    .eventwait        = sam_eventwait,
+    .callbackenable   = sam_callbackenable,
+    .registercallback = sam_registercallback,
 #ifdef CONFIG_SDIO_DMA
 #ifndef HSCMI_NORXDMA
-  .dmarecvsetup     = sam_dmarecvsetup,
+    .dmarecvsetup     = sam_dmarecvsetup,
 #else
-  .dmarecvsetup     = sam_recvsetup,
+    .dmarecvsetup     = sam_recvsetup,
 #endif
 #ifndef HSCMI_NOTXDMA
-  .dmasendsetup     = sam_dmasendsetup,
+    .dmasendsetup     = sam_dmasendsetup,
 #else
-  .dmasendsetup     = sam_sendsetup,
+    .dmasendsetup     = sam_sendsetup,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style changes to the 3rd commit.
   



##########
arch/arm/src/sama5/sam_hsmci.c:
##########
@@ -596,57 +596,145 @@ static void sam_callback(void *arg);
  * Private Data
  ****************************************************************************/
 
-/* Callbacks */
+/* Pre-allocate memory for each HSMCI device */
 
-static const struct sdio_dev_s g_callbacks =
+#ifdef CONFIG_SAMA5_HSMCI0
+static struct sam_dev_s g_hsmci0 =
 {
-  .reset            = sam_reset,
-  .capabilities     = sam_capabilities,
-  .status           = sam_status,
-  .widebus          = sam_widebus,
-  .clock            = sam_clock,
-  .attach           = sam_attach,
-  .sendcmd          = sam_sendcmd,
-  .blocksetup       = sam_blocksetup,
-  .recvsetup        = sam_recvsetup,
-  .sendsetup        = sam_sendsetup,
-  .cancel           = sam_cancel,
-  .waitresponse     = sam_waitresponse,
-  .recv_r1          = sam_recvshort,
-  .recv_r2          = sam_recvlong,
-  .recv_r3          = sam_recvshort,
-  .recv_r4          = sam_recvnotimpl,
-  .recv_r5          = sam_recvnotimpl,
-  .recv_r6          = sam_recvshort,
-  .recv_r7          = sam_recvshort,
-  .waitenable       = sam_waitenable,
-  .eventwait        = sam_eventwait,
-  .callbackenable   = sam_callbackenable,
-  .registercallback = sam_registercallback,
+  .dev                =
+  {
+    .reset            = sam_reset,
+    .capabilities     = sam_capabilities,
+    .status           = sam_status,
+    .widebus          = sam_widebus,
+    .clock            = sam_clock,
+    .attach           = sam_attach,
+    .sendcmd          = sam_sendcmd,
+    .blocksetup       = sam_blocksetup,
+    .recvsetup        = sam_recvsetup,
+    .sendsetup        = sam_sendsetup,
+    .cancel           = sam_cancel,
+    .waitresponse     = sam_waitresponse,
+    .recv_r1          = sam_recvshort,
+    .recv_r2          = sam_recvlong,
+    .recv_r3          = sam_recvshort,
+    .recv_r4          = sam_recvnotimpl,
+    .recv_r5          = sam_recvnotimpl,
+    .recv_r6          = sam_recvshort,
+    .recv_r7          = sam_recvshort,
+    .waitenable       = sam_waitenable,
+    .eventwait        = sam_eventwait,
+    .callbackenable   = sam_callbackenable,
+    .registercallback = sam_registercallback,
 #ifdef CONFIG_SDIO_DMA
 #ifndef HSCMI_NORXDMA
-  .dmarecvsetup     = sam_dmarecvsetup,
+    .dmarecvsetup     = sam_dmarecvsetup,
 #else
-  .dmarecvsetup     = sam_recvsetup,
+    .dmarecvsetup     = sam_recvsetup,
 #endif
 #ifndef HSCMI_NOTXDMA
-  .dmasendsetup     = sam_dmasendsetup,
+    .dmasendsetup     = sam_dmasendsetup,
 #else
-  .dmasendsetup     = sam_sendsetup,
+    .dmasendsetup     = sam_sendsetup,
 #endif
 #endif
+  },
+  .waitsem            = SEM_INITIALIZER(0),
+  .base               = SAM_HSMCI0_VBASE,
+  .hsmci              = 0,
 };
-
-/* Pre-allocate memory for each HSMCI device */
-
-#ifdef CONFIG_SAMA5_HSMCI0
-static struct sam_dev_s g_hsmci0;
 #endif
 #ifdef CONFIG_SAMA5_HSMCI1
-static struct sam_dev_s g_hsmci1;
+static struct sam_dev_s g_hsmci1 =
+{
+  .dev                =
+  {
+    .reset            = sam_reset,
+    .capabilities     = sam_capabilities,
+    .status           = sam_status,
+    .widebus          = sam_widebus,
+    .clock            = sam_clock,
+    .attach           = sam_attach,
+    .sendcmd          = sam_sendcmd,
+    .blocksetup       = sam_blocksetup,
+    .recvsetup        = sam_recvsetup,
+    .sendsetup        = sam_sendsetup,
+    .cancel           = sam_cancel,
+    .waitresponse     = sam_waitresponse,
+    .recv_r1          = sam_recvshort,
+    .recv_r2          = sam_recvlong,
+    .recv_r3          = sam_recvshort,
+    .recv_r4          = sam_recvnotimpl,
+    .recv_r5          = sam_recvnotimpl,
+    .recv_r6          = sam_recvshort,
+    .recv_r7          = sam_recvshort,
+    .waitenable       = sam_waitenable,
+    .eventwait        = sam_eventwait,
+    .callbackenable   = sam_callbackenable,
+    .registercallback = sam_registercallback,
+#ifdef CONFIG_SDIO_DMA
+#ifndef HSCMI_NORXDMA
+    .dmarecvsetup     = sam_dmarecvsetup,
+#else
+    .dmarecvsetup     = sam_recvsetup,
+#endif
+#ifndef HSCMI_NOTXDMA
+    .dmasendsetup     = sam_dmasendsetup,
+#else
+    .dmasendsetup     = sam_sendsetup,

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_hsmci.c:
##########
@@ -3232,11 +3315,6 @@ struct sdio_dev_s *sdio_initialize(int slotno)
 
       priv = &g_hsmci1;
 
-      /* HSMCI1 Initialization */
-
-      priv->base  = SAM_HSMCI1_VBASE;
-      priv->hsmci = 1;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_hsmci.c:
##########
@@ -596,57 +596,145 @@ static void sam_callback(void *arg);
  * Private Data
  ****************************************************************************/
 
-/* Callbacks */
+/* Pre-allocate memory for each HSMCI device */
 
-static const struct sdio_dev_s g_callbacks =
+#ifdef CONFIG_SAMA5_HSMCI0
+static struct sam_dev_s g_hsmci0 =
 {
-  .reset            = sam_reset,
-  .capabilities     = sam_capabilities,
-  .status           = sam_status,
-  .widebus          = sam_widebus,
-  .clock            = sam_clock,
-  .attach           = sam_attach,
-  .sendcmd          = sam_sendcmd,
-  .blocksetup       = sam_blocksetup,
-  .recvsetup        = sam_recvsetup,
-  .sendsetup        = sam_sendsetup,
-  .cancel           = sam_cancel,
-  .waitresponse     = sam_waitresponse,
-  .recv_r1          = sam_recvshort,
-  .recv_r2          = sam_recvlong,
-  .recv_r3          = sam_recvshort,
-  .recv_r4          = sam_recvnotimpl,
-  .recv_r5          = sam_recvnotimpl,
-  .recv_r6          = sam_recvshort,
-  .recv_r7          = sam_recvshort,
-  .waitenable       = sam_waitenable,
-  .eventwait        = sam_eventwait,
-  .callbackenable   = sam_callbackenable,
-  .registercallback = sam_registercallback,
+  .dev                =
+  {
+    .reset            = sam_reset,
+    .capabilities     = sam_capabilities,
+    .status           = sam_status,
+    .widebus          = sam_widebus,
+    .clock            = sam_clock,
+    .attach           = sam_attach,
+    .sendcmd          = sam_sendcmd,
+    .blocksetup       = sam_blocksetup,
+    .recvsetup        = sam_recvsetup,
+    .sendsetup        = sam_sendsetup,
+    .cancel           = sam_cancel,
+    .waitresponse     = sam_waitresponse,
+    .recv_r1          = sam_recvshort,
+    .recv_r2          = sam_recvlong,
+    .recv_r3          = sam_recvshort,
+    .recv_r4          = sam_recvnotimpl,
+    .recv_r5          = sam_recvnotimpl,
+    .recv_r6          = sam_recvshort,
+    .recv_r7          = sam_recvshort,
+    .waitenable       = sam_waitenable,
+    .eventwait        = sam_eventwait,
+    .callbackenable   = sam_callbackenable,
+    .registercallback = sam_registercallback,
 #ifdef CONFIG_SDIO_DMA
 #ifndef HSCMI_NORXDMA
-  .dmarecvsetup     = sam_dmarecvsetup,
+    .dmarecvsetup     = sam_dmarecvsetup,
 #else
-  .dmarecvsetup     = sam_recvsetup,
+    .dmarecvsetup     = sam_recvsetup,
 #endif
 #ifndef HSCMI_NOTXDMA
-  .dmasendsetup     = sam_dmasendsetup,
+    .dmasendsetup     = sam_dmasendsetup,
 #else
-  .dmasendsetup     = sam_sendsetup,
+    .dmasendsetup     = sam_sendsetup,
 #endif
 #endif
+  },
+  .waitsem            = SEM_INITIALIZER(0),
+  .base               = SAM_HSMCI0_VBASE,
+  .hsmci              = 0,
 };
-
-/* Pre-allocate memory for each HSMCI device */
-
-#ifdef CONFIG_SAMA5_HSMCI0
-static struct sam_dev_s g_hsmci0;
 #endif
 #ifdef CONFIG_SAMA5_HSMCI1
-static struct sam_dev_s g_hsmci1;
+static struct sam_dev_s g_hsmci1 =
+{
+  .dev                =
+  {
+    .reset            = sam_reset,
+    .capabilities     = sam_capabilities,
+    .status           = sam_status,
+    .widebus          = sam_widebus,
+    .clock            = sam_clock,
+    .attach           = sam_attach,
+    .sendcmd          = sam_sendcmd,
+    .blocksetup       = sam_blocksetup,
+    .recvsetup        = sam_recvsetup,
+    .sendsetup        = sam_sendsetup,
+    .cancel           = sam_cancel,
+    .waitresponse     = sam_waitresponse,
+    .recv_r1          = sam_recvshort,
+    .recv_r2          = sam_recvlong,
+    .recv_r3          = sam_recvshort,
+    .recv_r4          = sam_recvnotimpl,
+    .recv_r5          = sam_recvnotimpl,
+    .recv_r6          = sam_recvshort,
+    .recv_r7          = sam_recvshort,
+    .waitenable       = sam_waitenable,
+    .eventwait        = sam_eventwait,
+    .callbackenable   = sam_callbackenable,
+    .registercallback = sam_registercallback,
+#ifdef CONFIG_SDIO_DMA
+#ifndef HSCMI_NORXDMA
+    .dmarecvsetup     = sam_dmarecvsetup,
+#else
+    .dmarecvsetup     = sam_recvsetup,
+#endif
+#ifndef HSCMI_NOTXDMA
+    .dmasendsetup     = sam_dmasendsetup,
+#else
+    .dmasendsetup     = sam_sendsetup,
+#endif
+#endif
+  },
+  .waitsem            = SEM_INITIALIZER(0),
+  .base               = SAM_HSMCI0_VBASE,
+  .hsmci              = 0,
+};
 #endif
 #ifdef CONFIG_SAMA5_HSMCI2
-static struct sam_dev_s g_hsmci2;
+static struct sam_dev_s g_hsmci2 =
+{
+  .dev                =
+  {
+    .reset            = sam_reset,
+    .capabilities     = sam_capabilities,
+    .status           = sam_status,
+    .widebus          = sam_widebus,
+    .clock            = sam_clock,
+    .attach           = sam_attach,
+    .sendcmd          = sam_sendcmd,
+    .blocksetup       = sam_blocksetup,
+    .recvsetup        = sam_recvsetup,
+    .sendsetup        = sam_sendsetup,
+    .cancel           = sam_cancel,
+    .waitresponse     = sam_waitresponse,
+    .recv_r1          = sam_recvshort,
+    .recv_r2          = sam_recvlong,
+    .recv_r3          = sam_recvshort,
+    .recv_r4          = sam_recvnotimpl,
+    .recv_r5          = sam_recvnotimpl,
+    .recv_r6          = sam_recvshort,
+    .recv_r7          = sam_recvshort,
+    .waitenable       = sam_waitenable,
+    .eventwait        = sam_eventwait,
+    .callbackenable   = sam_callbackenable,
+    .registercallback = sam_registercallback,

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_ohci.c:
##########
@@ -4202,10 +4201,6 @@ struct usbhost_connection_s *sam_ohci_initialize(int controller)
 
   usbhost_vtrace1(OHCI_VTRACE1_INITIALIZED, 0);
 
-  /* Initialize and return the connection interface */
-
-  g_ohciconn.wait      = sam_wait;
-  g_ohciconn.enumerate = sam_enumerate;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_hsmci.c:
##########
@@ -3312,16 +3385,6 @@ struct sdio_dev_s *sdio_initialize(int slotno)
          " hsmci: %d dmac: %d pid: %" PRId32 "\n",
          priv, priv->base, priv->hsmci, dmac, pid);
 
-  /* Initialize the HSMCI slot structure */
-
-  /* Initialize semaphores */
-
-  nxsem_init(&priv->waitsem, 0, 0);
-
-  /* Initialize the callbacks */
-
-  memcpy(&priv->dev, &g_callbacks, sizeof(struct sdio_dev_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_ohci.c:
##########
@@ -4023,10 +4026,6 @@ struct usbhost_connection_s *sam_ohci_initialize(int controller)
 
   usbhost_vtrace1(OHCI_VTRACE1_INITIALIZING, 0);
 
-  /* Initialize all the HCCA to 0 */
-
-  memset((void *)&g_hcca, 0, sizeof(struct ohci_hcca_s));

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_hsmci.c:
##########
@@ -3193,11 +3281,6 @@ struct sdio_dev_s *sdio_initialize(int slotno)
 
       priv = &g_hsmci0;
 
-      /* HSMCI0 Initialization */
-
-      priv->base  = SAM_HSMCI0_VBASE;
-      priv->hsmci = 0;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_tc.c:
##########
@@ -98,10 +98,7 @@ struct sam_chconfig_s
 
 struct sam_tcconfig_s
 {
-  uintptr_t base;          /* TC register base address */
-  uint8_t pid;             /* Peripheral ID */
   uint8_t chfirst;         /* First channel number */
-  uint8_t tc;              /* Timer/counter number */

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_hsmci.c:
##########
@@ -3271,11 +3349,6 @@ struct sdio_dev_s *sdio_initialize(int slotno)
 
       priv = &g_hsmci2;
 
-      /* HSMCI2 Initialization */
-
-      priv->base  = SAM_HSMCI2_VBASE;
-      priv->hsmci = 2;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_ohci.c:
##########
@@ -3110,7 +3118,7 @@ static int sam_ctrlin(struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
   struct sam_rhport_s *rhport = (struct sam_rhport_s *)drvr;
   struct sam_eplist_s *eplist = (struct sam_eplist_s *)ep0;
   uint16_t len;
-  int  ret;
+  int ret;

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/sama5/sam_tc.c:
##########
@@ -201,10 +198,7 @@ static inline struct sam_chan_s *sam_tc_initialize(int channel);
 #ifdef CONFIG_SAMA5_TC0
 static const struct sam_tcconfig_s g_tc012config =
 {
-  .base    = SAM_TC012_VBASE,
-  .pid     = SAM_PID_TC0,
   .chfirst = 0,
-  .tc      = 0,

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?



##########
arch/arm/src/sama5/sam_tc.c:
##########
@@ -271,10 +265,7 @@ static const struct sam_tcconfig_s g_tc012config =
 #ifdef CONFIG_SAMA5_TC1
 static const struct sam_tcconfig_s g_tc345config =
 {
-  .base    = SAM_TC345_VBASE,
-  .pid     = SAM_PID_TC1,
   .chfirst = 3,
-  .tc      = 1,

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_tc.c:
##########
@@ -341,10 +332,7 @@ static const struct sam_tcconfig_s g_tc345config =
 #ifdef CONFIG_SAMA5_TC2
 static const struct sam_tcconfig_s g_tc678config =
 {
-  .base    = SAM_TC678_VBASE,
-  .pid     = SAM_PID_TC2,
   .chfirst = 6,
-  .tc      = 2,

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_tc.c:
##########
@@ -411,15 +399,33 @@ static const struct sam_tcconfig_s g_tc678config =
 /* Timer/counter state */
 
 #ifdef CONFIG_SAMA5_TC0
-static struct sam_tc_s g_tc012;
+static struct sam_tc_s g_tc012 =
+{
+  .lock = NXMUTEX_INITIALIZER,
+  .base = SAM_TC012_VBASE,
+  .pid  = SAM_PID_TC0,
+  .tc   = 0,
+};

Review Comment:
   @xiaoxiang781216 
   Do these changes except for `.lock` relate to the global mutex/sem initialization?
    



##########
arch/arm/src/sama5/sam_tc.c:
##########
@@ -411,15 +399,33 @@ static const struct sam_tcconfig_s g_tc678config =
 /* Timer/counter state */
 
 #ifdef CONFIG_SAMA5_TC0
-static struct sam_tc_s g_tc012;
+static struct sam_tc_s g_tc012 =
+{
+  .lock = NXMUTEX_INITIALIZER,
+  .base = SAM_TC012_VBASE,
+  .pid  = SAM_PID_TC0,
+  .tc   = 0,
+};
 #endif
 
 #ifdef CONFIG_SAMA5_TC1
-static struct sam_tc_s g_tc345;
+static struct sam_tc_s g_tc345 =
+{
+  .lock = NXMUTEX_INITIALIZER,
+  .base = SAM_TC345_VBASE,
+  .pid  = SAM_PID_TC1,
+  .tc   = 1,
+};

Review Comment:
   @xiaoxiang781216 
   Do these changes except for .lock relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_trng.c:
##########
@@ -333,15 +337,6 @@ static int sam_rng_initialize(void)
 
   finfo("Initializing TRNG hardware\n");
 
-  /* Initialize the device structure */
-
-  memset(&g_trngdev, 0, sizeof(struct trng_dev_s));

Review Comment:
   @xiaoxiang781216 
   Does this chang relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_tc.c:
##########
@@ -954,19 +960,11 @@ static inline struct sam_chan_s *sam_tc_initialize(int channel)
   flags = enter_critical_section();
   if (!tc->initialized)
     {
-      /* Initialize the timer counter data structure. */
-
-      memset(tc, 0, sizeof(struct sam_tc_s));
-      nxmutex_init(&tc->lock);
-      tc->base = tcconfig->base;
-      tc->tc   = channel < 3 ? 0 : 1;
-      tc->pid  = tcconfig->pid;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_tc.c:
##########
@@ -1008,7 +1006,7 @@ static inline struct sam_chan_s *sam_tc_initialize(int channel)
 
       /* Set the maximum TC peripheral clock frequency */
 
-      regval  = PMC_PCR_PID(tcconfig->pid) | PMC_PCR_CMD | PMC_PCR_EN;
+      regval  = PMC_PCR_PID(tc->pid) | PMC_PCR_CMD | PMC_PCR_EN;

Review Comment:
   @xiaoxiang781216 
   Does this chang relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_tc.c:
##########
@@ -954,19 +960,11 @@ static inline struct sam_chan_s *sam_tc_initialize(int channel)
   flags = enter_critical_section();
   if (!tc->initialized)
     {
-      /* Initialize the timer counter data structure. */
-
-      memset(tc, 0, sizeof(struct sam_tc_s));
-      nxmutex_init(&tc->lock);
-      tc->base = tcconfig->base;
-      tc->tc   = channel < 3 ? 0 : 1;
-      tc->pid  = tcconfig->pid;
-
       /* Initialize the channels */
 
       for (i = 0, ch = tcconfig->chfirst; i < SAM_TC_NCHANNELS; i++)
         {
-          tmrerr("ERROR: Initializing TC%d channel %d\n", tcconfig->tc, ch);
+          tmrerr("ERROR: Initializing TC%d channel %d\n", tc->tc, ch);

Review Comment:
   @xiaoxiang781216 
   Does this chang relate to the global mutex/sem initialization?



##########
arch/arm/src/sama5/sam_tsd.c:
##########
@@ -245,7 +245,12 @@ static const struct file_operations g_tsdops =
 
 /* The driver state structure is pre-allocated. */
 
-static struct sam_tsd_s g_tsd;
+static struct sam_tsd_s g_tsd =
+{
+  .threshx = INVALID_THRESHOLD,
+  .threshy = INVALID_THRESHOLD,
+  .waitsem = SEM_INITIALIZER(0),

Review Comment:
   @xiaoxiang781216 
   Do these changes except for .waitsem relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_tc.c:
##########
@@ -411,15 +399,33 @@ static const struct sam_tcconfig_s g_tc678config =
 /* Timer/counter state */
 
 #ifdef CONFIG_SAMA5_TC0
-static struct sam_tc_s g_tc012;
+static struct sam_tc_s g_tc012 =
+{
+  .lock = NXMUTEX_INITIALIZER,
+  .base = SAM_TC012_VBASE,
+  .pid  = SAM_PID_TC0,
+  .tc   = 0,
+};
 #endif
 
 #ifdef CONFIG_SAMA5_TC1
-static struct sam_tc_s g_tc345;
+static struct sam_tc_s g_tc345 =
+{
+  .lock = NXMUTEX_INITIALIZER,
+  .base = SAM_TC345_VBASE,
+  .pid  = SAM_PID_TC1,
+  .tc   = 1,
+};
 #endif
 
 #ifdef CONFIG_SAMA5_TC2
-static struct sam_tc_s g_tc678;
+static struct sam_tc_s g_tc678 =
+{
+  .lock = NXMUTEX_INITIALIZER,
+  .base = SAM_TC678_VBASE,
+  .pid  = SAM_PID_TC2,
+  .tc   = 2,
+};

Review Comment:
   @xiaoxiang781216 
   Do these changes except for .lock relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_tc.c:
##########
@@ -1020,7 +1018,7 @@ static inline struct sam_chan_s *sam_tc_initialize(int channel)
 
       /* Enable clocking to the timer counter */
 
-      sam_enableperiph0(tcconfig->pid);
+      sam_enableperiph0(tc->pid);

Review Comment:
   Does this chang relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_tsd.c:
##########
@@ -1650,11 +1655,7 @@ int sam_tsd_register(struct sam_adc_s *adc, int minor)
 
   /* Initialize the touchscreen device driver instance */
 
-  memset(priv, 0, sizeof(struct sam_tsd_s));
-  priv->adc     = adc;               /* Save the ADC device handle */
-  priv->threshx = INVALID_THRESHOLD; /* Initialize thresholding logic */
-  priv->threshy = INVALID_THRESHOLD; /* Initialize thresholding logic */

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_tsd.c:
##########
@@ -1665,18 +1666,14 @@ int sam_tsd_register(struct sam_adc_s *adc, int minor)
   if (ret < 0)
     {
       ierr("ERROR: register_driver() failed: %d\n", ret);
-      goto errout_with_priv;
+      return ret;

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_twi.c:
##########
@@ -1177,55 +1213,39 @@ struct i2c_master_s *sam_i2cbus_initialize(int bus)
 #ifdef CONFIG_SAMA5_TWI0
   if (bus == 0)
     {
-      /* Select up TWI0 and setup invariant attributes */
-
-      priv       = &g_twi0;
-      priv->attr = &g_twi0attr;
-
-      /* Select the (initial) TWI frequency */
+      /* Select up TWI0 and the (initial) TWI frequency */
 
+      priv      = &g_twi0;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_twi.c:
##########
@@ -229,6 +229,14 @@ static void twi_hw_initialize(struct twi_dev_s *priv, uint32_t frequency);
  * Private Data
  ****************************************************************************/
 
+static const struct i2c_ops_s g_twiops =
+{
+  .transfer = twi_transfer
+#ifdef CONFIG_I2C_RESET
+  , .reset  = twi_reset
+#endif
+};
+

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_twi.c:
##########
@@ -1177,55 +1213,39 @@ struct i2c_master_s *sam_i2cbus_initialize(int bus)
 #ifdef CONFIG_SAMA5_TWI0
   if (bus == 0)
     {
-      /* Select up TWI0 and setup invariant attributes */
-
-      priv       = &g_twi0;
-      priv->attr = &g_twi0attr;
-
-      /* Select the (initial) TWI frequency */
+      /* Select up TWI0 and the (initial) TWI frequency */
 
+      priv      = &g_twi0;
       frequency = CONFIG_SAMA5_TWI0_FREQUENCY;
     }
   else
 #endif
 #ifdef CONFIG_SAMA5_TWI1
   if (bus == 1)
     {
-      /* Select up TWI1 and setup invariant attributes */
-
-      priv       = &g_twi1;
-      priv->attr = &g_twi1attr;
-
-      /* Select the (initial) TWI frequency */
+      /* Select up TWI1 and the (initial) TWI frequency */
 
+      priv      = &g_twi1;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_twi.c:
##########
@@ -254,7 +271,16 @@ static const struct twi_attr_s g_twi1attr =
   .base    = SAM_TWI1_VBASE,
 };
 
-static struct twi_dev_s g_twi1;
+static struct twi_dev_s g_twi1 =
+{
+  .dev     =
+  {
+    .ops   = &g_twiops,
+  },
+  .attr    = &g_twi1attr,

Review Comment:
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_twi.c:
##########
@@ -268,7 +294,16 @@ static const struct twi_attr_s g_twi2attr =
   .base    = SAM_TWI2_VBASE,
 };
 
-static struct twi_dev_s g_twi2;
+static struct twi_dev_s g_twi2 =
+{
+  .dev     =
+  {
+    .ops   = &g_twiops,
+  },
+  .attr    = &g_twi2attr,

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_twi.c:
##########
@@ -1177,55 +1213,39 @@ struct i2c_master_s *sam_i2cbus_initialize(int bus)
 #ifdef CONFIG_SAMA5_TWI0
   if (bus == 0)
     {
-      /* Select up TWI0 and setup invariant attributes */
-
-      priv       = &g_twi0;
-      priv->attr = &g_twi0attr;
-
-      /* Select the (initial) TWI frequency */
+      /* Select up TWI0 and the (initial) TWI frequency */
 
+      priv      = &g_twi0;
       frequency = CONFIG_SAMA5_TWI0_FREQUENCY;
     }
   else
 #endif
 #ifdef CONFIG_SAMA5_TWI1
   if (bus == 1)
     {
-      /* Select up TWI1 and setup invariant attributes */
-
-      priv       = &g_twi1;
-      priv->attr = &g_twi1attr;
-
-      /* Select the (initial) TWI frequency */
+      /* Select up TWI1 and the (initial) TWI frequency */
 
+      priv      = &g_twi1;
       frequency = CONFIG_SAMA5_TWI1_FREQUENCY;
     }
   else
 #endif
 #ifdef CONFIG_SAMA5_TWI2
   if (bus == 2)
     {
-      /* Select up TWI2 and setup invariant attributes */
-
-      priv       = &g_twi2;
-      priv->attr = &g_twi2attr;
-
-      /* Select the (initial) TWI frequency */
+      /* Select up TWI2 and the (initial) TWI frequency */
 
+      priv      = &g_twi2;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_twi.c:
##########
@@ -282,16 +317,17 @@ static const struct twi_attr_s g_twi3attr =
   .base    = SAM_TWI3_VBASE,
 };
 
-static struct twi_dev_s g_twi3;
-#endif
-
-static const struct i2c_ops_s g_twiops =
+static struct twi_dev_s g_twi3 =
 {
-  .transfer = twi_transfer
-#ifdef CONFIG_I2C_RESET
-  , .reset  = twi_reset
-#endif
+  .dev     =
+  {
+    .ops   = &g_twiops,
+  },
+  .attr    = &g_twi3attr,

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_twi.c:
##########
@@ -240,7 +248,16 @@ static const struct twi_attr_s g_twi0attr =
   .base    = SAM_TWI0_VBASE,
 };
 
-static struct twi_dev_s g_twi0;
+static struct twi_dev_s g_twi0 =
+{
+  .dev     =
+  {
+    .ops   = &g_twiops,
+  },
+  .attr    = &g_twi0attr,

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_xdmac.c:
##########
@@ -713,13 +716,16 @@ static struct sam_xdmach_s g_xdmach1[SAM_NDMACHAN] =
 
 static struct sam_xdmac_s g_xdmac1 =
 {
+  .chlock     = NXMUTEX_INITIALIZER,
+  .dsem       = SEM_INITIALIZER(SAM_NDMACHAN),
+
   /* XDMAC 0 base address */
 
   .base       = SAM_XDMAC1_VBASE,
 
   /* This array describes the available link list descriptors */
 
-  .descr       = g_desc1,
+  .descr      = g_desc1,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/sama5/sam_xdmac.c:
##########
@@ -539,13 +539,16 @@ static struct sam_xdmach_s g_xdmach0[SAM_NDMACHAN] =
 
 static struct sam_xdmac_s g_xdmac0 =
 {
+  .chlock     = NXMUTEX_INITIALIZER,
+  .dsem       = SEM_INITIALIZER(SAM_NDMACHAN),
+
   /* XDMAC 0 base address */
 
   .base       = SAM_XDMAC0_VBASE,
 
   /* This array describes the available link list descriptors */
 
-  .descr       = g_desc0,
+  .descr      = g_desc0,

Review Comment:
   @xiaoxiang781216 
   It would be better to move the style change to the 3rd commit.
   



##########
arch/arm/src/sama5/sam_xdmac.c:
##########
@@ -1522,7 +1510,7 @@ static void sam_freelinklist(struct sam_xdmach_s *xdmach)
        */
 
       memset(descr, 0, sizeof(struct chnext_view1_s));
-      sam_givedsem(xdmac);
+      nxsem_post(&xdmac->dsem);

Review Comment:
   @xiaoxiang781216 
   Does this change relate to the global mutex/sem initialization?
   



##########
arch/arm/src/sama5/sam_twi.c:
##########
@@ -1177,55 +1213,39 @@ struct i2c_master_s *sam_i2cbus_initialize(int bus)
 #ifdef CONFIG_SAMA5_TWI0
   if (bus == 0)
     {
-      /* Select up TWI0 and setup invariant attributes */
-
-      priv       = &g_twi0;
-      priv->attr = &g_twi0attr;
-
-      /* Select the (initial) TWI frequency */
+      /* Select up TWI0 and the (initial) TWI frequency */
 
+      priv      = &g_twi0;
       frequency = CONFIG_SAMA5_TWI0_FREQUENCY;
     }
   else
 #endif
 #ifdef CONFIG_SAMA5_TWI1
   if (bus == 1)
     {
-      /* Select up TWI1 and setup invariant attributes */
-
-      priv       = &g_twi1;
-      priv->attr = &g_twi1attr;
-
-      /* Select the (initial) TWI frequency */
+      /* Select up TWI1 and the (initial) TWI frequency */
 
+      priv      = &g_twi1;
       frequency = CONFIG_SAMA5_TWI1_FREQUENCY;
     }
   else
 #endif
 #ifdef CONFIG_SAMA5_TWI2
   if (bus == 2)
     {
-      /* Select up TWI2 and setup invariant attributes */
-
-      priv       = &g_twi2;
-      priv->attr = &g_twi2attr;
-
-      /* Select the (initial) TWI frequency */
+      /* Select up TWI2 and the (initial) TWI frequency */
 
+      priv      = &g_twi2;
       frequency = CONFIG_SAMA5_TWI2_FREQUENCY;
     }
   else
 #endif
 #ifdef CONFIG_SAMA5_TWI3
   if (bus == 3)
     {
-      /* Select up TWI3 and setup invariant attributes */
-
-      priv       = &g_twi3;
-      priv->attr = &g_twi3attr;
-
-      /* Select the (initial) TWI frequency */
+      /* Select up TWI3 and the (initial) TWI frequency */
 
+      priv      = &g_twi3;

Review Comment:
   @xiaoxiang781216 
   Do these changes relate to the global mutex/sem initialization?
   



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org