Changeset 4b44de57 in mainline for uspace/drv/time/cmos-rtc/cmos-rtc.c


Ignore:
Timestamp:
2012-04-01T20:19:01Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
28ca043f
Parents:
0883de8
Message:

RTC: invoke the cleanup function in case of errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/time/cmos-rtc/cmos-rtc.c

    r0883de8 r4b44de57  
    7979rtc_pio_enable(rtc_t *rtc);
    8080
     81static void
     82rtc_dev_cleanup(rtc_t *rtc);
     83
    8184
    8285static ddf_dev_ops_t rtc_dev_ops;
     
    113116}
    114117
     118/** Clean up the RTC soft state
     119 *
     120 * @param rtc  The RTC device
     121 */
     122static void
     123rtc_dev_cleanup(rtc_t *rtc)
     124{
     125        if (rtc->dev->parent_sess) {
     126                async_hangup(rtc->dev->parent_sess);
     127                rtc->dev->parent_sess = NULL;
     128        }
     129}
     130
    115131/** Enable the I/O ports of the device
    116132 *
     
    142158rtc_dev_initialize(rtc_t *rtc)
    143159{
    144         /* XXX Do cleanup in case of failure */
    145160        int rc;
    146161        size_t i;
     
    160175                ddf_msg(LVL_ERROR, "Failed to connect to parent driver\
    161176                    of device %s.", rtc->dev->name);
    162                 return ENOENT;
     177                rc = ENOENT;
     178                goto error;
    163179        }
    164180
     
    168184                ddf_msg(LVL_ERROR, "Failed to get HW resources\
    169185                    for device %s", rtc->dev->name);
    170                 return rc;
     186                goto error;
    171187        }
    172188
     
    186202                ddf_msg(LVL_ERROR, "Missing HW resource for device %s",
    187203                    rtc->dev->name);
    188                 return ENOENT;
     204                rc = ENOENT;
     205                goto error;
    189206        }
    190207
     
    192209
    193210        return EOK;
     211
     212error:
     213        rtc_dev_cleanup(rtc);
     214        hw_res_clean_resource_list(&hw_resources);
     215
     216        return rc;
    194217}
    195218
     
    230253{
    231254        rtc_t *rtc;
    232         ddf_fun_t *fun;
     255        ddf_fun_t *fun = NULL;
    233256        int rc;
     257        bool need_cleanup = false;
    234258
    235259        ddf_msg(LVL_DEBUG, "rtc_dev_add %s (handle = %d)",
     
    245269        rc = rtc_dev_initialize(rtc);
    246270        if (rc != EOK)
    247                 return rc;
    248 
    249         /* XXX Need cleanup */
    250         if (!rtc_pio_enable(rtc))
    251                 return EADDRNOTAVAIL;
     271                goto error;
     272
     273        need_cleanup = true;
     274
     275        if (!rtc_pio_enable(rtc)) {
     276                rc = EADDRNOTAVAIL;
     277                goto error;
     278        }
    252279
    253280        fun = ddf_fun_create(dev, fun_exposed, "a");
    254281        if (!fun) {
    255282                ddf_msg(LVL_ERROR, "Failed creating function");
    256                 return ENOENT;
     283                rc = ENOENT;
     284                goto error;
    257285        }
    258286
     
    261289        if (rc != EOK) {
    262290                ddf_msg(LVL_ERROR, "Failed binding function");
    263                 return rc;
     291                goto error;
    264292        }
    265293
     
    271299            dev->name);
    272300
     301        return rc;
     302
     303error:
     304        if (fun)
     305                ddf_fun_destroy(fun);
     306        if (need_cleanup)
     307                rtc_dev_cleanup(rtc);
    273308        return rc;
    274309}
Note: See TracChangeset for help on using the changeset viewer.