Fix kernel panic if cache->nelms is zero.

MFC after:	2 weeks
This commit is contained in:
Alexander Motin 2013-09-06 14:31:52 +00:00
parent ef70de180c
commit d7a52e7b49

View File

@ -567,8 +567,8 @@ ses_cache_free_elm_addlstatus(enc_softc_t *enc, enc_cache_t *cache)
return;
for (cur_elm = cache->elm_map,
last_elm = &cache->elm_map[cache->nelms - 1];
cur_elm <= last_elm; cur_elm++) {
last_elm = &cache->elm_map[cache->nelms];
cur_elm != last_elm; cur_elm++) {
ses_element_t *elmpriv;
elmpriv = cur_elm->elm_private;
@ -598,8 +598,8 @@ ses_cache_free_elm_descs(enc_softc_t *enc, enc_cache_t *cache)
return;
for (cur_elm = cache->elm_map,
last_elm = &cache->elm_map[cache->nelms - 1];
cur_elm <= last_elm; cur_elm++) {
last_elm = &cache->elm_map[cache->nelms];
cur_elm != last_elm; cur_elm++) {
ses_element_t *elmpriv;
elmpriv = cur_elm->elm_private;
@ -644,8 +644,8 @@ ses_cache_free_elm_map(enc_softc_t *enc, enc_cache_t *cache)
ses_cache_free_elm_descs(enc, cache);
ses_cache_free_elm_addlstatus(enc, cache);
for (cur_elm = cache->elm_map,
last_elm = &cache->elm_map[cache->nelms - 1];
cur_elm <= last_elm; cur_elm++) {
last_elm = &cache->elm_map[cache->nelms];
cur_elm != last_elm; cur_elm++) {
ENC_FREE_AND_NULL(cur_elm->elm_private);
}
@ -717,8 +717,8 @@ ses_cache_clone(enc_softc_t *enc, enc_cache_t *src, enc_cache_t *dst)
dst->elm_map = ENC_MALLOCZ(dst->nelms * sizeof(enc_element_t));
memcpy(dst->elm_map, src->elm_map, dst->nelms * sizeof(enc_element_t));
for (dst_elm = dst->elm_map, src_elm = src->elm_map,
last_elm = &src->elm_map[src->nelms - 1];
src_elm <= last_elm; src_elm++, dst_elm++) {
last_elm = &src->elm_map[src->nelms];
src_elm != last_elm; src_elm++, dst_elm++) {
dst_elm->elm_private = ENC_MALLOCZ(sizeof(ses_element_t));
memcpy(dst_elm->elm_private, src_elm->elm_private,