From patchwork Mon Mar 3 10:06:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 3753231 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3DBC8BF13A for ; Mon, 3 Mar 2014 10:15:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5C1902012F for ; Mon, 3 Mar 2014 10:15:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F7522009C for ; Mon, 3 Mar 2014 10:15:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754678AbaCCKPB (ORCPT ); Mon, 3 Mar 2014 05:15:01 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:49397 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754168AbaCCKH7 (ORCPT ); Mon, 3 Mar 2014 05:07:59 -0500 Received: from [201.74.152.26] (helo=smtp.w2.samsung.com) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1WKPmu-00078I-2l; Mon, 03 Mar 2014 10:07:57 +0000 Received: from mchehab by smtp.w2.samsung.com with local (Exim 4.80.1) (envelope-from ) id 1WKPmF-0006Wo-BE; Mon, 03 Mar 2014 07:07:15 -0300 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab Subject: [PATCH 39/79] [media] drx-j: Be sure that all allocated data are properly initialized Date: Mon, 3 Mar 2014 07:06:33 -0300 Message-Id: <1393841233-24840-40-git-send-email-m.chehab@samsung.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1393841233-24840-1-git-send-email-m.chehab@samsung.com> References: <1393841233-24840-1-git-send-email-m.chehab@samsung.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The state struct is allocated without cleaning the memory. This causes random bugs. Clean it, and move the memcpy functions just below each kalloc, to be clearer that all those data are properly filled. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb-frontends/drx39xyj/drx39xxj.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/media/dvb-frontends/drx39xyj/drx39xxj.c b/drivers/media/dvb-frontends/drx39xyj/drx39xxj.c index 44e9bafcc9ed..a19547b08b02 100644 --- a/drivers/media/dvb-frontends/drx39xyj/drx39xxj.c +++ b/drivers/media/dvb-frontends/drx39xyj/drx39xxj.c @@ -342,7 +342,7 @@ struct dvb_frontend *drx39xxj_attach(struct i2c_adapter *i2c) int result; /* allocate memory for the internal state */ - state = kmalloc(sizeof(struct drx39xxj_state), GFP_KERNEL); + state = kzalloc(sizeof(struct drx39xxj_state), GFP_KERNEL); if (state == NULL) goto error; @@ -353,39 +353,38 @@ struct dvb_frontend *drx39xxj_attach(struct i2c_adapter *i2c) demod_addr = kmalloc(sizeof(struct i2c_device_addr), GFP_KERNEL); if (demod_addr == NULL) goto error; + memcpy(demod_addr, &drxj_default_addr_g, + sizeof(struct i2c_device_addr)); demod_comm_attr = kmalloc(sizeof(struct drx_common_attr), GFP_KERNEL); if (demod_comm_attr == NULL) goto error; + memcpy(demod_comm_attr, &drxj_default_comm_attr_g, + sizeof(struct drx_common_attr)); demod_ext_attr = kmalloc(sizeof(struct drxj_data), GFP_KERNEL); if (demod_ext_attr == NULL) goto error; + memcpy(demod_ext_attr, &drxj_data_g, sizeof(struct drxj_data)); /* setup the state */ state->i2c = i2c; state->demod = demod; + /* setup the demod data */ memcpy(demod, &drxj_default_demod_g, sizeof(struct drx_demod_instance)); demod->my_i2c_dev_addr = demod_addr; - memcpy(demod->my_i2c_dev_addr, &drxj_default_addr_g, - sizeof(struct i2c_device_addr)); - demod->my_i2c_dev_addr->user_data = state; demod->my_common_attr = demod_comm_attr; - memcpy(demod->my_common_attr, &drxj_default_comm_attr_g, - sizeof(struct drx_common_attr)); + demod->my_i2c_dev_addr->user_data = state; demod->my_common_attr->microcode = DRXJ_MC_MAIN; #if 0 demod->my_common_attr->verify_microcode = false; #endif demod->my_common_attr->verify_microcode = true; demod->my_common_attr->intermediate_freq = 5000; - demod->my_ext_attr = demod_ext_attr; - memcpy(demod->my_ext_attr, &drxj_data_g, sizeof(struct drxj_data)); - ((struct drxj_data *)demod->my_ext_attr)->uio_sma_tx_mode = DRX_UIO_MODE_READWRITE; - + ((struct drxj_data *)demod_ext_attr)->uio_sma_tx_mode = DRX_UIO_MODE_READWRITE; demod->my_tuner = NULL; result = drx_open(demod);