Kaynağa Gözat

msm: camera: core: Prevent crash on kref_put

kref_put causes crash if refcount is zero.
This change prevents crash by checking if refcount value.

CRs-Fixed: 2553290
Change-Id: Ie9a950b289cdb2b8fca8c5d025be540d926eadbd
Signed-off-by: Trishansh Bhardwaj <[email protected]>
Trishansh Bhardwaj 5 yıl önce
ebeveyn
işleme
5f530223ba
1 değiştirilmiş dosya ile 6 ekleme ve 1 silme
  1. 6 1
      drivers/cam_core/cam_context.c

+ 6 - 1
drivers/cam_core/cam_context.c

@@ -597,7 +597,12 @@ int cam_context_deinit(struct cam_context *ctx)
 
 
 void cam_context_putref(struct cam_context *ctx)
 void cam_context_putref(struct cam_context *ctx)
 {
 {
-	kref_put(&ctx->refcount, cam_node_put_ctxt_to_free_list);
+	if (kref_read(&ctx->refcount))
+		kref_put(&ctx->refcount, cam_node_put_ctxt_to_free_list);
+	else
+		WARN(1, "ctx %s %d state %d devhdl %X\n", ctx->dev_name,
+			ctx->ctx_id, ctx->state, ctx->dev_hdl);
+
 	CAM_DBG(CAM_CORE,
 	CAM_DBG(CAM_CORE,
 		"ctx device hdl %ld, ref count %d, dev_name %s",
 		"ctx device hdl %ld, ref count %d, dev_name %s",
 		ctx->dev_hdl, refcount_read(&(ctx->refcount.refcount)),
 		ctx->dev_hdl, refcount_read(&(ctx->refcount.refcount)),